sandip chitale's blog    Sandip Chitale's blog (scblog)
NOTE: I have moved many of my modules to NetBeans Plugin Portal . Please check there for latest versions of modules described on this blog.
20060521 Sunday May 21, 2006

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 Comments [0]


Trackback URL: http://blogs.sun.com/scblog/entry/tip_images_in_tooltips
Comments:

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed








« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

Get NetBeans 5.5

Locations of visitors to this page

Today's Page Hits: 501


XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

XML
All
/Creator
/General
/Hobby
/Java
/JavaScript
/Mozilla
/NetBeans
/Ubuntu
/VisualWeb
/VisualWebPack
/Web 2.0

scblog
scblog