errorPopup= popFactory.getPopup(this, errorBox,
(verifierTopComponent.super.getX()+verifierTopComponent.super.getWidth()/2),
(verifierTopComponent.super.getY()+verifierTopComponent.super.getHeight()/2));
上面的代码可以正常工作,并且正确地将弹出窗口居中...但只有当窗口是全屏时,才能在我的主显示器上。
如何让它更强大?我想把它放在当前RCP实例的中间。
(verifierTopComponent是模块中错误命名的TopComponent)。
在下面的评论之后,我想知道你们是否通常会使用一种截然不同的方法创建一个弹出窗口?我只是想在用户的脸上放一些东西让他们知道为什么事情不会像他们那样完成。
答案 0 :(得分:0)
使用NetBeans RCP时,您应该使用DialogDisplayer和DialogDescriptor
这样的事情:
DialogDescriptor dd = new DialogDescriptor(errorBox, "Error message");
Object result = DialogDisplayer.getDefault().notify(dd);
它会自动计算正确的位置。
答案 1 :(得分:0)
我不确定如何解决您的具体问题但根据我的经验,您可以/应该使用NetBeans的org.openide.NotifyDescriptor
类向用户显示通知。您需要为模块添加Dialog API的依赖项以使用以下内容。
NotifyDescriptor nd = new NotifyDescriptor(
"This is the message that will go in the main body of the message. This could also be a custom JPanel",
"Title of Dialog",
NotifyDescriptor.DEFAULT_OPTION,
NotifyDescriptor.ERROR_MESSAGE,
null, // this could be an array of JButtons that will replace the dialog's built-in buttons
NotifyDescriptor.OK_OPTION);
Object returnedValue = DialogDisplayer.getDefault().notify(nd);
if (returnedValue == NotifyDescriptor.OK_OPTION) {
// user pressed OK button
}
与往常一样,请参阅javadoc for NotifyDescriptor了解详情
编辑如另一个答案中所述,您可以使用扩展NotifyDescriptor类的DialogDescriptor类,并添加将对话框设置为模态以及其他一些有用功能的功能。
还有一些其他有用的类扩展了NotifyDescriptor类,可能对其他情况有用。有关子类列表,请参阅NotifyDescriptor的javadoc。