|
URL Example with Desktop class |
The given code in the DispalyTooltip.java file has a label component. Whenever we move the mouse on the particular component, a related tooltip is displayed with the specified text.
DispalyTooltip.java
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JToolTip;
public class DisplayTooltip {
public static void main(String args[]) {
String title = “Tooltip Sample”;
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation
(JFrame.EXIT_ON_CLOSE);
Container container =
frame.getContentPane();
JPanel panel = new JPanel();
panel.setToolTipText(“<HtMl>
Tooltip<br>Message”);
container.add(panel,
BorderLayout.CENTER);
JLabel label = new JLabel(“Hello World”) {
public JToolTip createToolTip() {
JToolTip tip = super.createToolTip();
tip.setBackground(Color.red);
tip.setForeground(Color.green);
return tip;
}
public boolean contains(int x, int y) {
if (x < 100) {
setToolTipText(“Got Component”);
} else {
setToolTipText(“Got Frame”);
}
return super.contains(x, y);
}
};
label.setToolTipText(“Hello World”);
frame.getContentPane().add(label,
BorderLayout.NORTH);
frame.setSize(300, 150);
frame.setVisible(true);
}
} |
|
Lets see the outputs from the three kinds of
ToolTips.
1. Move the mouse on the Label component.

2. Move mouse outside of the component area.

3. Move mouse outside of the frame area.

Download Example
3. Shuffle the elements of a Collection using ArrayList interface. |
|
|
March 2008 | Java Jazz Up | 53 |
|
|
View All Topics |
All Pages of this Issue |
Pages:
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,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
Download PDF |
|
|
Mar
2008 | Java Jazz Up | 53 |
|
|
View All Topics |
All Pages of this Issue |
Pages:
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,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
Download PDF |
|
|
|
|
|
|
|
|
|