Add tooltip to Swing controls in Java
Description
The following code shows how to add tooltip to Swing controls.
Example
//from w ww. j a v a 2 s . c om
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 b = new JButton("Hello, World");
frame.add(b,"Center");
b.setToolTipText("asdf");
frame.setSize(300, 200);
frame.setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »