Java中如何禁用/启用应用程序工具提示?
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);
}
}
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短