errael commented on code in PR #5280:
URL: https://github.com/apache/netbeans/pull/5280#discussion_r1074033974
##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1345,8 +1362,8 @@ public static Component findDialogParent() {
parent =
KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
}
if (parent == null) {
- Frame[] f = Frame.getFrames();
- parent = f.length == 0 ? null : f[f.length - 1];
+ // PR#5280
+ parent = findMainWindow();
Review Comment:
> @errael I would possibly fall back to the original behaviour if the search
for the main window returns null.
The original behavior is severely flawed. Take a look in the comment that
opened this PR, under **notes on Utilities.findDialogParent**. And from the
javadoc for Frame.getFrames()
```
Warning: this method may return system created frames, such as a shared,
hidden frame which
is used by Swing. Applications should not assume the existence of these
frames, nor should an
application assume anything about these frames such as component positions,
LayoutManagers
or serialization.
```
> Ideally it wouldn't use the name to find the right window, but that might
be the easiest way to achieve.
Notice that this technique is already in use in this file. May have to do
with dependencies. This PR encapsulates its use in a method so at least it's
not buried.
> I have no idea how many people (if any!) use `FileChoooserBuilder` outside
of the standard window system, but this will change the behaviour of those
cases.
If someone explicitly wants random dialog placement there are probably more
interesting ways. I believe this case rarely comes up AFAIK, I've just been
lucky.
A null owner is probably more consistent (better?).
If this is a strong concern for `FileChooserBuilder`, then suggest using a
private version of `findDialogParent()` with the old code rather than
propagate buggy behavior in a new-ish public API.
(Aside: I've wondered about use of non standard window system; are there any
known examples in "production"? )
--
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