How do I disable/enable application tool tips?

package org.kodejava.swing;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.WindowConstants;
import java.awt.FlowLayout;
import java.awt.HeadlessException;

public class DisableToolTip extends JFrame {
    public DisableToolTip() throws HeadlessException {
        initComponent();
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new DisableToolTip().setVisible(true));
    }

    private void initComponent() {
        setSize(500, 500);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));

        JButton disable = new JButton("DISABLE");
        disable.setToolTipText("Application tool tip will be disabled.");
        disable.addActionListener(e -> {
            // Disable tool tip for the entire application
            ToolTipManager.sharedInstance().setEnabled(false);
        });

        JButton enable = new JButton("ENABLE");
        enable.setToolTipText("Application tool tip will be enabled.");
        enable.addActionListener(e -> {
            // Enable tool tip for the entire application
            ToolTipManager.sharedInstance().setEnabled(true);
        });

        getContentPane().add(enable);
        getContentPane().add(disable);
    }
}
Disable or Enable Tool Tips

Disable or Enable Tool Tips

Wayan

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.