package org.nhooo.example.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(300, 300); 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 -> { // 禁用整个应用程序的工具提示 ToolTipManager.sharedInstance().setEnabled(false); }); JButton enable = new JButton("ENABLE"); enable.setToolTipText("Application tool tip will be enabled."); enable.addActionListener(e -> { // 为整个应用程序启用工具提示 ToolTipManager.sharedInstance().setEnabled(true); }); getContentPane().add(enable); getContentPane().add(disable); } }