Disable / enable application tool tips : JToolTip « Swing « Java Tutorial






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);
  }
}








14.72.JToolTip
14.72.1.Adding JToolTip to componentAdding JToolTip to component
14.72.2.Creating HTML 3.2 formatted text tooltip: the text string begins with 'html' in any caseCreating HTML 3.2 formatted text tooltip: the text string begins with 'html' in any case
14.72.3.Creating Customized JToolTip Objects: customize and override its inherited public JToolTip createToolTip()
14.72.4.Displaying Positional Tooltip Text: display different tooltip depending on the mouse pointer's location
14.72.5.Displaying Mnemonics in tooltip textDisplaying Mnemonics in tooltip text
14.72.6.Label with tooltip
14.72.7.Use images in tooltips
14.72.8.Make a tool tips appear immediately
14.72.9.Use the default tool tip location
14.72.10.Setting the Location of a Tool Tip
14.72.11.Enabling and Disabling Tool Tips
14.72.12.Showing an Image in a Tool Tip
14.72.13.Italicize the second line
14.72.14.By default, the lines are left justified. Center the lines.
14.72.15.Showing Multiple Lines in a Tool Tip
14.72.16.Disable / enable application tool tips
14.72.17.Making Tool Tips Remain Visible
14.72.18.Set the location of the tool tip such that its nw corner coincides with the bottom center of the button
14.72.19.Modify the behaviour of the default JToolTip
14.72.20.Customizing a JToolTip Look and Feel