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 父亲祝福语大全简短语