Enable and Disabling Tool Tips in Java

Description

The following code shows how to enable and Disabling Tool Tips.

Example


  /*  w  w  w.  ja v a2 s.  c o m*/
  

 
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.ToolTipManager;

public class Main extends JFrame {
  public Main() throws HeadlessException {
    setSize(300, 300);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));

    JButton disable = new JButton("DISABLE");
    disable.setToolTipText("disabled.");
    disable.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ToolTipManager.sharedInstance().setEnabled(false);
      }
    });
    JButton enable = new JButton("ENABLE");
    enable.setToolTipText("enabled.");
    enable.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ToolTipManager.sharedInstance().setEnabled(true);
      }
    });
    getContentPane().add(enable);
    getContentPane().add(disable);
  }

  public static void main(String[] args) {
    new Main().setVisible(true);
  }
}

The code above generates the following result.

Enable and Disabling Tool Tips in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer