|
How to use images in tooltips |
|
|
The Swing tooltips support html syntax via use of the 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:
Source: sandip chitale's blog
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.