errael opened a new pull request, #5280: URL: https://github.com/apache/netbeans/pull/5280
When placing a dialog through NetBeans' API, if no focused component is found then use NbMainWindow. Change fallback for Utilities.findDialogParent to use NbMainWindow. @matthiasblaesing , @neilcsmith-net , @mbien alerting since you made comments on previous PR. This PR is a follow on to https://github.com/apache/netbeans/pull/4739. Wanted to open a bigger change earlier in the cycle, but... So this is a minimal change, hopefully more to come next cycle with detailed examination of cases from https://github.com/apache/netbeans/discussions/4887. There are situations where ``` null == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); ``` And also related methods such as `getFocusOwner()`, `getActiveWindow()` are `null`. What happens is `NbPresenter.findFocusedWindow()` returns null and the logic in `NbPresenter.initBounds()` ends up doing `Utilities.findCenterBounds(size)` which does `Utilities.getCurrentGraphicsConfiguration()` and ends up on the default screen instead of a screen that NetBeans is on. The bigger change I've been thinking about addresses some issues with `Utilities.getCurrentGraphicsConfiguration()` and would put the dialog on the same screen as NetBeans is on, but even better is to have the dialog *over the Window that NetBeans is in*. This PR does that with a hack to `NbPresenter.findFocusedWindow()`; taken from Utilities. In `NbPresenter.initBounds()`, can consider `Utilities.findDialogParent()` instead of the local `findFocusedWindow()`, and then make sure that whatever's returned is a window. In any event, with this change the else clause is unlikely to ever be executed; just as well, notice the comment for the else clause: ``` //just center the dialog on the screen and let's hope it'll be //the correct one in multi-monitor setup ``` ### notes on Utilities.findDialogParent There was some discussion in the dialog parent PR https://github.com/apache/netbeans/pull/4739#discussion_r997414384 from last release about the `Utilities.findDialogParent()` fallback. Investigation for this PR showed a situation where a fallback is needed, and the current fallback is not good. Frame.getFrames() comes from a Vector<WeakReference<Window>>; doing garbage collection shortens the array. Here's an example I saw, the fallback ``` parent = f.length == 0 ? null : f[f.length - 1]; ``` selects the last item and is choosing something ripe for garbage collection. Notice in this case the 2nd entry is the main window. ``` f Frame[] #16829(length=6) #16829(length=6) [0] Frame #16831 java.awt.Frame[frame0,2640,390,480x300,invalid,hidden, [1] JFrame #16832 javax.swing.JFrame[NbMainWindow,2566,544,1274x505,inva [2] Popup$DefaultFrame #16833 javax.swing.Popup$DefaultFrame[frame3, [3] Popup$DefaultFrame #16778 javax.swing.Popup$DefaultFrame[frame2, [4] Popup$DefaultFrame #16834 javax.swing.Popup$DefaultFrame[frame4, [5] Popup$DefaultFrame #16835 javax.swing.Popup$DefaultFrame[frame5, ``` These entries are like: ``` javax.swing.Popup$DefaultFrame[frame5,0,32,0x0,invalid,hidden ``` This PR makes the change to use the main window as fallback. This was previously proposed, but was deferred pending clarification on whether a fallback was needed at all. -- 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
