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 卡片祝福语幽默简短英文