3

How to get the mouseover effects on JButton which should be similar to the effect which we will get on mouseover of tags in Stackoveflow? E.G.

Pop-up help

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
svkvvenky
  • 1,122
  • 1
  • 15
  • 21

3 Answers3

5

See JComponent.setToolTipText(String). The tool-tip supports HTML to some extent, but not to the extent of providing the functionality of the links at the bottom of the SO tag pop-ups.

To do that, you'd need to swap the tool-tip for a JWindow/JEditorPane where you'd need to 'wire it together' yourself. Here is an example that uses a JWindow (to display BufferedImage instances).

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
3

You can use setRolloverIcon. Here is an example.

tenorsax
  • 21,123
  • 9
  • 60
  • 107
1
Icon normalIcon = new ImageIcon("normal-icon.png"); // Icon for normal situations
JButton button = new JButton(); // initialize the button
button.setIcon(normalIcon); // set the normal situation icon

Icon rollOverIcon = new ImageIcon("roll-over.png"); // Icon for roll over (hovering effect)
button.setRolloverIcon(rollOverIcon); // Set the icon attaching with the roll-over event
GingerHead
  • 8,130
  • 15
  • 59
  • 93