Java Swing How to - Load tooltip image from URL








Question

We would like to know how to load tooltip image from URL.

Answer

//  ww w.j  a v  a2 s .  co  m
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main {

  public static void main(String[] args) throws Exception {
    final String html = "<html><body>" + "<img src='"
        + "http://www.java2s.com/style/download.png"
        + "' width=160 height=120> " + "<img src='"
        + "http://www.java2s.com/style/download.png"
        + "' width=160 height=120>" + "<p>Message!";

    JLabel hover = new JLabel("Point at me!");
    hover.setToolTipText(html);
    JOptionPane.showMessageDialog(null, hover);

  }
}