Java Swing How to - Set tooltip for JButton








Question

We would like to know how to set tooltip for JButton.

Answer

import javax.swing.JButton;
import javax.swing.JOptionPane;
//from   w ww. j  av a2  s  .c  om
public class Main {
  public static void main(final String args[]) {
    JButton button = new JButton("Test");
    button.setToolTipText("Help text for the button");

    JOptionPane.showMessageDialog(null, button);
  }
}