Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Adding JToolTip to component

Tooltip text is normally one line long. Calling the public void setToolTipText(String text) method from JComponent to create a tooltip. import javax.swing.JButton; import javax.swing.JFrame; public class ToolTipDemo {   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);   } }