errael commented on code in PR #4739:
URL: https://github.com/apache/netbeans/pull/4739#discussion_r997503878
##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1325,6 +1325,32 @@ private static Rectangle
findCenterBounds(GraphicsConfiguration gconf, Dimension
);
}
+ /**
+ * This is for use in situations where a standard swing API,
+ * such as {@linkplain JOptionPane.show*} or {@linkplain
JFileChooser.show*},
+ * is used to display a dialog. {@code null} should never be used
+ * as a dialog's parent because it
+ * frequently does the wrong thing in a multi-screen setup.
+ * <p>
+ * The use of the NetBeans API
+ * {@linkplain DialogDisplayer.getDefault.*}
+ * is encouraged to display a dialog, but stuff happens.
+ * @return A suitable parent component for swing dialog displayers.
+ * @since 9.26
+ */
+ // PR4739
+ public static Component findDialogParent() {
+ Component parent =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+ if (parent == null) {
+ parent =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
+ }
+ if (parent == null) {
+ Frame[] f = Frame.getFrames();
+ parent = f.length == 0 ? null : f[f.length - 1];
Review Comment:
Oh yeah, it looks like
```
// KFM is out of it, check out known frames
if (parent == null) {
Frame[] frames = Frame.getFrames();
for( Frame f : frames ) {
if( "NbMainWindow".equals(f.getName())) { //NOI18N
parent = f;
break;
}
}
if(parent == null && frames.length != 0)
parent = frames[frames.length - 1];
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists