TIP: Images in Tooltips
Here is a simple tip:
The Swing tooltips support html syntax via use of the <html> tag. This can be exploited to show images in tooltips.
For example, with the following layout:
src
org
mypackage
ImageInTooltip.java
tooltip.gif
and source code:
package org.mypackage;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class ImageInTooltip {
public static void main(String[] args) {
JFrame frame = new JFrame();
JLabel label = new JLabel("Label with image in Tooltip!");
label.setToolTipText(
"<html><img src=\"" +
ImageInTooltip.class.getResource("tooltip.gif") +
"\"> Tooltip "
);
label.setHorizontalAlignment(JLabel.CENTER);
frame.setContentPane(label);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 200, 100);
frame.setVisible(true);
}
}
give you this:
Posted by sandipchitale
( May 21 2006, 04:59:23 PM PDT ) Permalink
Trackback URL: http://blogs.sun.com/scblog/entry/tip_images_in_tooltips