1

Basically, I need an image/icon to show up whenI hover over a swing component

//this is what i normally use to apply image to components
Icon icon = new ImageIcon(getClass().getResource("icon.png"));
label = new JLabel(icon);

what I'd like to do:

 //use an imported icon on a tool tip text and also add some texts
 label.setToolTipText(icon + "some random text");
Guy Sirton
  • 8,331
  • 2
  • 26
  • 36
Shadowkillsa
  • 77
  • 1
  • 8

1 Answers1

4

Tool tips support HTML, so display that image as you might display it in HTML. E.G. as seen in this answer.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • i dont know that programming language – Shadowkillsa Mar 03 '14 at 06:51
  • 1
    HTML is not a programming language. – Andrew Thompson Mar 03 '14 at 06:51
  • ok i got it to work, but how do i replace the links to the picture on the internet by links to pictures in a folder on my computer, iv tried everything i know about links but it just wont do it – Shadowkillsa Mar 03 '14 at 16:21
  • 1
    *"how do i replace the links to the picture on the internet by links to pictures in a folder on my computer"* Use what you originally used. `getClass().getResource("icon.png")` What do you think that returns, a pony? – Andrew Thompson Mar 04 '14 at 06:03
  • @AndrewThompson I think he means the image links in the HTML. The tooltip, not his icon. (and yeah, it wasn't part of his original question) – Guy Sirton Mar 04 '14 at 21:34