Java Swing How to - Add tooltip to JLabel








Question

We would like to know how to add tooltip to JLabel.

Answer

import javax.swing.JLabel;
import javax.swing.JOptionPane;
/*from  w  w w .  j  a v a 2 s  . co  m*/
public class Main {
  public static void main(String[] args) {
    JLabel label = new JLabel("Username :", JLabel.RIGHT);
    
    label.setToolTipText("A tool tip with me!");
    
    JOptionPane.showMessageDialog(null, label);
    
  }
}