[英]Java Swing show tooltip as a message dialog
Is it possible in Java Swing to show message box using tooltip item. 在Java Swing中是否可以使用工具提示项显示消息框。 I need to show tooltip not only when a mouse hovers some component but also when I choose specific item in context menu of this component when tooltips are turned off.
我不仅需要在鼠标悬停某个组件时显示工具提示,还需要在关闭工具提示时在该组件的上下文菜单中选择特定项目时显示工具提示。
You can use PopupFactory to show your popup message 您可以使用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();
where myComponent - is the component for which popup must be shown 其中myComponent-是必须为其显示弹出窗口的组件
x, y - coordinates of popup. x,y-弹出窗口的坐标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.