Java Swing 中是否可以使用工具提示项显示消息框。我不仅需要在鼠标悬停在某个组件上时显示工具提示,而且还需要在关闭工具提示时在该组件的上下文菜单中选择特定项目时显示工具提示。
最佳答案
您可以使用 PopupFactory 来显示弹出消息
final Popup p = PopupFactory.getSharedInstance().getPopup(myComponent, new JLabel("Here is my popup!"), x, y);
p.show();
// create a timer to hide the popup later
Timer t = new Timer(5000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
p.hide();
}
});
t.setRepeats(false);
t.start();
其中 myComponent - 是必须显示弹出窗口的组件
x, y - 弹出窗口的坐标。
关于Java Swing 将工具提示显示为消息对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39955015/