سؤال

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

The code above works, and properly centers the popup... but only if the window is fullscreen, on my main monitor.

How do I make it more robust? I'd like to center it in the middle of the current RCP instance.

(verifierTopComponent is my incorrectly named TopComponent in the module).

After the comment below, I'm wondering if maybe y'all typically use a vastly different method to create a popup? I'm just trying to put something in the user's face to let them know why things won't work as they have done them.

هل كانت مفيدة؟

المحلول

When using the NetBeans RCP you should rather use DialogDisplayer and DialogDescriptor

Something like this:

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

It will automatically take care of calculating the correct position.

نصائح أخرى

I'm unsure how to solve your specific issue but in my experience you can/should use NetBeans' org.openide.NotifyDescriptor class to show notifications to the user. You will need to add a dependency for the Dialog API to your module to use the following.

    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
    }

As always, see the javadoc for NotifyDescriptor for more info

Edit As described in another answer you could use the DialogDescriptor class which extends the NotifyDescriptor class and adds the ability to set the dialog to modal along with a couple of other useful features.

There are also a couple of other useful classes that extend the NotifyDescriptor class that may be useful for other situations. See the javadoc for NotifyDescriptor for a list of subclasses.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top