Java Swing How to - Show box on hover of item in Tooltip








Question

We would like to know how to show box on hover of item in Tooltip.

Answer

import javax.swing.JLabel;
import javax.swing.JOptionPane;
/* ww w  .  j  a v a 2  s  . c o m*/
public class Main {
  public static void main(String[] args) {
    String html = "<html><body>" + "<h1>Header</h1>"
        + "<img src='http://www.java2s.com/style/download.png' "
        + "width='160' height='120'>";
    JLabel label = new JLabel("Point at me!");
    label.setToolTipText(html);
    JOptionPane.showMessageDialog(null, label);
  }
}