neilcsmith-net commented on code in PR #4739:
URL: https://github.com/apache/netbeans/pull/4739#discussion_r997994903
##########
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:
I am strongly inclined to leave the code as a verbatim move of the code from
`FileChooserBuilder` for now - that is used a lot across the IDE already.
Let's use as is for the additional cases unless there's a proven issue to
address.
While the documentation `Frame::getFrames` is a bit odd, I'm curious how
often that fallback is ever hit here? Have you tried a breakpoint? If it's
rare/never then changing it is pointless. If it's commonly hit, then special
casing `NbMainWindow` may be a change in logic that actually ends up being less
correct.
--
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