0
 errorPopup= popFactory.getPopup(this, errorBox, 
                    (verifierTopComponent.super.getX()+verifierTopComponent.super.getWidth()/2),
                    (verifierTopComponent.super.getY()+verifierTopComponent.super.getHeight()/2));

上面的代码有效,并且正确地将弹出窗口居中......但前提是窗口是全屏的,在我的主监视器上。

如何让它更健壮?我想把它放在当前 RCP 实例的中间。

(verifierTopComponent 是我在模块中错误命名的 TopComponent)。

在下面的评论之后,我想知道你们是否通常使用完全不同的方法来创建弹出窗口?我只是想把一些东西放在用户的脸上,让他们知道为什么事情不会像他们那样工作。

4

2 回答 2

0

使用 NetBeans RCP 时,您应该使用DialogDisplayerDialogDescriptor

像这样的东西:

DialogDescriptor dd = new DialogDescriptor(errorBox, "Error message");
Object result = DialogDisplayer.getDefault().notify(dd);

它将自动负责计算正确的位置。

于 2011-11-22T22:09:08.190 回答
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
    }

与往常一样,请参阅NotifyDescriptor 的 javadoc 以获取更多信息

编辑如另一个答案中所述,您可以使用DialogDescriptor类,它扩展了 NotifyDescriptor 类并添加了将对话框设置为模态的能力以及其他一些有用的功能。

还有一些其他有用的类扩展了 NotifyDescriptor 类,这些类可能对其他情况有用。有关子类的列表,请参阅 NotifyDescriptor 的 javadoc。

于 2011-11-22T22:09:58.740 回答