Show Tooltip for different position in Java
Description
The following code shows how to show Tooltip for different position.
Example
// w w w .j av a 2 s .c o m
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main{
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Hello, World") {
public boolean contains(int x, int y) {
if (x < 50) {
setToolTipText("50 java2s.com");
} else {
setToolTipText("java2s.com");
}
return super.contains(x, y);
}
};
frame.add(button, "Center");
frame.setSize(300, 200);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »