errael commented on code in PR #4739:
URL: https://github.com/apache/netbeans/pull/4739#discussion_r997454046


##########
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:
   > The documentation of `Frame.getFrames` reads a bit strange. For NetBean I 
suggest to fall back to `WindowManager.getMainWindow` and if that indeed is not 
present, the return null.
   
   Strange indeed. `getMainWindow()` does seem a better fallback. (and acc'd to 
doc creates a frame if none exists.)
   
   I'll make that change, **please review carefully since I won't be able to 
test it**.



-- 
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

Reply via email to