Set tooltip for button in Java
Description
The following code shows how to set tooltip for button.
Example
/* w ww. ja v a2 s .c o m*/
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton b = new JButton("Test");
b.setToolTipText("Help text for the button");
add(b);
pack();
}
public static void main(String[] args) {
new Main().setVisible(true);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »