Skip to content

Commit 9164e39

Browse files
committed
When placing a dialog through NetBeans' API,
if no focused component is found then use NbMainWindow. Change fallback for Utilities.findDialogParent to use NbMainWindow.
1 parent d1c3913 commit 9164e39

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public void showDialog () {
225225
// if a modal dialog is active use it as parent
226226
// otherwise use the main window
227227

228-
NbPresenter presenter = null;
228+
NbPresenter presenter;
229229
if (descriptor instanceof DialogDescriptor) {
230230
if (NbPresenter.currentModalDialog != null) {
231231
if (NbPresenter.currentModalDialog.isLeaf ()) {
@@ -252,11 +252,8 @@ public void showDialog () {
252252
presenter = new NbPresenter(descriptor, NbPresenter.currentModalDialog, true);
253253
}
254254
} else {
255-
Frame f = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow()
256-
instanceof Frame ?
257-
(Frame) KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow()
258-
: WindowManager.getDefault().getMainWindow();
259-
255+
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
256+
Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow();
260257
if (noParent) {
261258
f = null;
262259
}

platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,18 @@ private void initBounds() {
15911591
*/
15921592
private Window findFocusedWindow() {
15931593
Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
1594+
if( w == null ) {
1595+
// PR#5280
1596+
LOG.fine( () -> "No focused window, find mainWindow" );
1597+
for( Frame f01 : Frame.getFrames() ) {
1598+
if( "NbMainWindow".equals(f01.getName())) { //NOI18N
1599+
if(f01.getWidth() != 0 || f01.getHeight() != 0) {
1600+
w = f01;
1601+
}
1602+
break;
1603+
}
1604+
}
1605+
}
15941606
while( null != w && !w.isShowing() ) {
15951607
w = w.getOwner();
15961608
}

platform/openide.util.ui/src/org/openide/util/Utilities.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,11 +1157,9 @@ private static GraphicsConfiguration getCurrentGraphicsConfiguration() {
11571157
return w.getGraphicsConfiguration();
11581158
} else {
11591159
//#217737 - try to find the main window which could be placed in secondary screen
1160-
for( Frame f : Frame.getFrames() ) {
1161-
if( "NbMainWindow".equals(f.getName())) { //NOI18N
1162-
return f.getGraphicsConfiguration();
1163-
}
1164-
}
1160+
Frame f = findMainWindow();
1161+
if(f != null)
1162+
return f.getGraphicsConfiguration();
11651163
}
11661164
}
11671165

@@ -1325,6 +1323,25 @@ private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension
13251323
);
13261324
}
13271325

1326+
/**
1327+
* Find the main NetBeans window; must have width or height.
1328+
* This is used locally to avoid dependency issues.
1329+
* @return NetBeans' main window
1330+
*/
1331+
private static Frame findMainWindow()
1332+
{
1333+
Frame f = null;
1334+
for( Frame f01 : Frame.getFrames() ) {
1335+
if( "NbMainWindow".equals(f01.getName())) { //NOI18N
1336+
if(f01.getWidth() != 0 || f01.getHeight() != 0) {
1337+
f = f01;
1338+
}
1339+
break;
1340+
}
1341+
}
1342+
return f;
1343+
}
1344+
13281345
/**
13291346
* This is for use in situations where a standard swing API,
13301347
* such as {@linkplain JOptionPane.show*} or {@linkplain JFileChooser.show*},
@@ -1345,8 +1362,8 @@ public static Component findDialogParent() {
13451362
parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
13461363
}
13471364
if (parent == null) {
1348-
Frame[] f = Frame.getFrames();
1349-
parent = f.length == 0 ? null : f[f.length - 1];
1365+
// PR#5280
1366+
parent = findMainWindow();
13501367
}
13511368
return parent;
13521369
}

0 commit comments

Comments
 (0)