You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ne...@apache.org on 2022/10/18 16:01:05 UTC

[netbeans] branch master updated: Don't use null parent for swing dialogs JOptionPane, JFileChooser. In a multi-screen setup, using null parent often puts the dialog on the wrong screen.

This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 52a037708b Don't use null parent for swing dialogs JOptionPane, JFileChooser. In a multi-screen setup, using null parent often puts the dialog on the wrong screen.
     new b0366bf0d9 Merge pull request #4739 from errael/DialogParentMainWindowInsteadOfNull
52a037708b is described below

commit 52a037708b4ad48312ba78adc6a12fc137d91e4d
Author: Ernie Rael <er...@raelity.com>
AuthorDate: Sat Oct 15 12:20:17 2022 -0700

    Don't use null parent for swing dialogs JOptionPane, JFileChooser.
    In a multi-screen setup, using null parent often puts the dialog
    on the wrong screen.
    
    Utilities.findDialogParent() copied from FileChooserBuilder.
    Manually change FileChoolerBuidler to use Utilities.
    Rest of the changes done with jackpot script:
    
    <?
    import org.openide.util.Utilities;
    ?>
    
    "chooser dialog null":
    $jfc.showOpenDialog(null) :: $jfc instanceof javax.swing.JFileChooser
    => $jfc.showOpenDialog(Utilities.findDialogParent())
    ;;
    
    "chooser dialog null":
    $jfc.showSaveDialog(null) :: $jfc instanceof javax.swing.JFileChooser
    => $jfc.showSaveDialog(Utilities.findDialogParent())
    ;;
    
    "JOptionPane-2a null parent":
        $jop.showConfirmDialog($parent, $rest$)
    ::  isNullLiteral($parent)
        && $jop instanceof javax.swing.JOptionPane
    =>  $jop.showConfirmDialog(Utilities.findDialogParent(), $rest$)
    ;;
    
    "JOptionPane-2b null parent":
        $jop.showMessageDialog($parent, $rest$)
    ::  isNullLiteral($parent)
        && $jop instanceof javax.swing.JOptionPane
    =>  $jop.showMessageDialog(Utilities.findDialogParent(), $rest$)
    ;;
    
    "JOptionPane-2c null parent":
        $jop.showOptionDialog($parent, $rest$)
    ::  isNullLiteral($parent)
        && $jop instanceof javax.swing.JOptionPane
    =>  $jop.showOptionDialog(Utilities.findDialogParent(), $rest$)
    ;;
---
 .../grailsproject/ui/GrailsPluginsPanel.java       |  3 ++-
 .../web/jsf/navigation/NavigationCaseEdge.java     |  3 ++-
 .../db/dataview/output/InsertRecordDialog.java     |  2 +-
 .../DataViewTableDataExportFileChooser.java        |  4 ++--
 .../netbeans/modules/git/ui/clone/CloneAction.java |  3 ++-
 .../modules/mercurial/ui/clone/CloneAction.java    |  2 +-
 .../modules/mercurial/ui/commit/CommitAction.java  |  3 ++-
 .../modules/mercurial/ui/diff/DiffAction.java      |  3 ++-
 .../modules/mercurial/ui/merge/MergeAction.java    | 11 ++++-----
 .../mercurial/ui/properties/HgProperties.java      |  3 ++-
 .../modules/mercurial/ui/pull/PullAction.java      |  5 +++--
 .../modules/mercurial/ui/push/PushAction.java      |  3 ++-
 .../mercurial/ui/queues/FailedPatchResolver.java   |  3 ++-
 .../mercurial/ui/rollback/RollbackAction.java      |  3 ++-
 .../netbeans/modules/mercurial/util/HgUtils.java   |  4 ++--
 .../project/ant/ProjectLibraryProvider.java        |  3 ++-
 .../options/DictionaryInstallerPanel.java          |  2 +-
 .../modules/subversion/ModuleLifecycleManager.java |  3 ++-
 .../ui/update/ResolveConflictsExecutor.java        |  2 +-
 .../subversion/ui/wcadmin/UpgradeAction.java       |  3 ++-
 .../queries/SourceJavadocAttacherUtil.java         |  2 +-
 .../java/project/ui/ProjectProblemsProviders.java  |  4 ++--
 .../netbeans/modules/maven/nodes/ModulesNode.java  |  3 ++-
 javafx/maven.htmlui/nbproject/project.xml          |  8 +++++++
 .../modules/maven/htmlui/DukeScriptWizard.java     |  5 +++--
 .../openide/filesystems/FileChooserBuilder.java    | 26 ++++------------------
 platform/openide.util.ui/apichanges.xml            | 16 +++++++++++++
 .../src/org/openide/util/Utilities.java            | 26 ++++++++++++++++++++++
 .../modules/templates/ui/TemplatesPanel.java       |  3 ++-
 .../ppoints/ui/LoadGeneratorCustomizer.java        |  3 ++-
 .../profiler/ppoints/ui/LocationCustomizer.java    |  3 ++-
 .../profiler/ppoints/ui/SnapshotCustomizer.java    |  3 ++-
 32 files changed, 111 insertions(+), 59 deletions(-)

diff --git a/contrib/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/ui/GrailsPluginsPanel.java b/contrib/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/ui/GrailsPluginsPanel.java
index f0832cf503..38763552e7 100644
--- a/contrib/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/ui/GrailsPluginsPanel.java
+++ b/contrib/groovy.grailsproject/src/org/netbeans/modules/groovy/grailsproject/ui/GrailsPluginsPanel.java
@@ -35,6 +35,7 @@ import org.netbeans.modules.groovy.grailsproject.GrailsProject;
 import org.netbeans.modules.groovy.grailsproject.plugins.GrailsPlugin;
 import org.netbeans.modules.groovy.grailsproject.plugins.GrailsPluginSupport;
 import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
 
 /**
  * @author David Calavera
@@ -462,7 +463,7 @@ private void pluginBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {
     chooser.setDialogTitle(NbBundle.getMessage(GrailsPluginsPanel.class, "TITLE_BrowsePluginLocation"));
     chooser.setApproveButtonText(NbBundle.getMessage(GrailsPluginsPanel.class, "LBL_BrowsePluginLocation_OK_Button"));
 
-    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+    if (chooser.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
         pluginZipPath.setText(chooser.getSelectedFile().getAbsolutePath());                                                  
         installButton.setEnabled(true);
     }
diff --git a/enterprise/web.jsf.navigation/src/org/netbeans/modules/web/jsf/navigation/NavigationCaseEdge.java b/enterprise/web.jsf.navigation/src/org/netbeans/modules/web/jsf/navigation/NavigationCaseEdge.java
index 2295c216e0..298b0ce57c 100644
--- a/enterprise/web.jsf.navigation/src/org/netbeans/modules/web/jsf/navigation/NavigationCaseEdge.java
+++ b/enterprise/web.jsf.navigation/src/org/netbeans/modules/web/jsf/navigation/NavigationCaseEdge.java
@@ -48,6 +48,7 @@ import org.openide.nodes.Sheet.Set;
 import org.openide.util.Exceptions;
 import org.openide.util.HelpCtx;
 import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
 
 /**
  *
@@ -137,7 +138,7 @@ public final class NavigationCaseEdge extends PageFlowSceneElement  {
             try { 
                 name =  navCase.getFromOutcome() != null ? navCase.getFromOutcome() : navCase.getFromAction();
             } catch (IllegalStateException ise){
-                JOptionPane.showMessageDialog(null, MSG_FacesConfigIllegalStateWarning, TLE_FacesConfigIllegalStateWarning, JOptionPane.WARNING_MESSAGE);
+                JOptionPane.showMessageDialog(Utilities.findDialogParent(), MSG_FacesConfigIllegalStateWarning, TLE_FacesConfigIllegalStateWarning, JOptionPane.WARNING_MESSAGE);
             }
         }
         return name;
diff --git a/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/InsertRecordDialog.java b/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/InsertRecordDialog.java
index 047a0bfdb3..f3b3a3a9be 100644
--- a/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/InsertRecordDialog.java
+++ b/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/InsertRecordDialog.java
@@ -549,7 +549,7 @@ private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIR
         int[] colsselected = insertRecordTableUI.getSelectedColumns();
         if (!((numrows - 1 == rowsselected[rowsselected.length - 1] - rowsselected[0] && numrows == rowsselected.length) &&
                 (numcols - 1 == colsselected[colsselected.length - 1] - colsselected[0] && numcols == colsselected.length))) {
-            JOptionPane.showMessageDialog(null, "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
+            JOptionPane.showMessageDialog(Utilities.findDialogParent(), "Invalid Copy Selection", "Invalid Copy Selection", JOptionPane.ERROR_MESSAGE);
             return;
         }
         for (int i = 0; i < numrows; i++) {
diff --git a/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/DataViewTableDataExportFileChooser.java b/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/DataViewTableDataExportFileChooser.java
index cc6a1252ce..d7ff976704 100644
--- a/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/DataViewTableDataExportFileChooser.java
+++ b/ide/db.dataview/src/org/netbeans/modules/db/dataview/output/dataexport/DataViewTableDataExportFileChooser.java
@@ -28,6 +28,7 @@ import javax.swing.filechooser.FileFilter;
 import org.netbeans.api.progress.BaseProgressUtils;
 import org.netbeans.modules.db.dataview.output.DataViewTableUIModel;
 import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
 
 /**
  *
@@ -76,8 +77,7 @@ public class DataViewTableDataExportFileChooser {
 
     private static boolean checkFile(File file) {
         if (file.exists()) {
-            int a = JOptionPane.showConfirmDialog(
-                    null,
+            int a = JOptionPane.showConfirmDialog(Utilities.findDialogParent(),
                     Bundle.LBL_OVEWRITE_DIALOG(),
                     Bundle.MSG_OVEWRITE_DIALOG(),
                     JOptionPane.YES_NO_OPTION);
diff --git a/ide/git/src/org/netbeans/modules/git/ui/clone/CloneAction.java b/ide/git/src/org/netbeans/modules/git/ui/clone/CloneAction.java
index 2a8fb5d53d..cd4b8f1ba1 100644
--- a/ide/git/src/org/netbeans/modules/git/ui/clone/CloneAction.java
+++ b/ide/git/src/org/netbeans/modules/git/ui/clone/CloneAction.java
@@ -71,6 +71,7 @@ import org.openide.util.Lookup;
 import org.openide.util.Mutex;
 import org.openide.util.NbBundle;
 import org.openide.util.RequestProcessor.Task;
+import org.openide.util.Utilities;
 
 /**
  *
@@ -271,7 +272,7 @@ public class CloneAction implements ActionListener, HelpCtx.Provider {
                             }
 
                             private boolean confirmSubmoduleInit (List<File> subrepos) {
-                                return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null,
+                                return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Utilities.findDialogParent(),
                                         Bundle.MSG_Clone_confirmSubmoduleInit_text(),
                                         Bundle.LBL_Clone_confirmSubmoduleInit_title(),
                                         JOptionPane.YES_NO_OPTION,
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java
index 4a7f4060e4..d905089531 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/clone/CloneAction.java
@@ -371,7 +371,7 @@ public class CloneAction extends ContextAction {
                 
                 OutputLogger logger = support.getLogger();
                 logger.outputInRed(NbBundle.getMessage(CloneAction.class, "MSG_CLONE_CANCEL_ATTEMPT")); // NOI18N
-                JOptionPane.showMessageDialog(null,
+                JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                     NbBundle.getMessage(CloneAction.class, "MSG_CLONE_CANCEL_NOT_SUPPORTED"),// NOI18N
                     NbBundle.getMessage(CloneAction.class, "MSG_CLONE_CANCEL_NOT_SUPPORTED_TITLE"),// NOI18N
                     JOptionPane.INFORMATION_MESSAGE);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/commit/CommitAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/commit/CommitAction.java
index f24c8b7e29..06d701293f 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/commit/CommitAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/commit/CommitAction.java
@@ -83,6 +83,7 @@ import org.openide.cookies.EditorCookie;
 import org.openide.cookies.SaveCookie;
 import org.openide.filesystems.FileUtil;
 import org.openide.nodes.Node;
+import org.openide.util.Utilities;
 
 /**
  * Commit action for mercurial:
@@ -148,7 +149,7 @@ public class CommitAction extends ContextAction {
                     NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
             logger.output(""); // NOI18N
             logger.closeLog();
-            JOptionPane.showMessageDialog(null,
+            JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                     NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_NOT_SUPPORTED_INVIEW"),// NOI18N
                     NbBundle.getMessage(CommitAction.class, "MSG_COMMIT_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
                     JOptionPane.INFORMATION_MESSAGE);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/diff/DiffAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/diff/DiffAction.java
index 3bf431d8c3..f2a62d3415 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/diff/DiffAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/diff/DiffAction.java
@@ -34,6 +34,7 @@ import org.netbeans.modules.mercurial.ui.actions.ContextAction;
 import org.netbeans.modules.mercurial.ui.log.HgLogMessage.HgRevision;
 import org.openide.nodes.Node;
 import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
 import static org.netbeans.modules.mercurial.ui.diff.Bundle.*;
 
 /**
@@ -89,7 +90,7 @@ public class DiffAction extends ContextAction {
                     NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
             logger.output(""); // NOI18N
             logger.closeLog();
-            JOptionPane.showMessageDialog(null,
+            JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                     NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW"),// NOI18N
                     NbBundle.getMessage(DiffAction.class, "MSG_DIFF_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
                     JOptionPane.INFORMATION_MESSAGE);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/merge/MergeAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/merge/MergeAction.java
index 949217d09a..36fd8fd54b 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/merge/MergeAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/merge/MergeAction.java
@@ -42,6 +42,7 @@ import org.netbeans.modules.mercurial.HgProgressSupport;
 import org.netbeans.modules.mercurial.ui.log.HgLogMessage;
 import org.openide.DialogDescriptor;
 import org.openide.nodes.Node;
+import org.openide.util.Utilities;
 
 /**
  * Merge action for mercurial:
@@ -84,7 +85,7 @@ public class MergeAction extends ContextAction {
                     NbBundle.getMessage(MergeAction.class, "MSG_MERGE_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N
             logger.output(""); // NOI18N
             logger.closeLog();
-            JOptionPane.showMessageDialog(null,
+            JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                     NbBundle.getMessage(MergeAction.class, "MSG_MERGE_NOT_SUPPORTED_INVIEW"),// NOI18N
                     NbBundle.getMessage(MergeAction.class, "MSG_MERGE_NOT_SUPPORTED_INVIEW_TITLE"),// NOI18N
                     JOptionPane.INFORMATION_MESSAGE);
@@ -103,7 +104,7 @@ public class MergeAction extends ContextAction {
                         logger.output( NbBundle.getMessage(MergeAction.class,"MSG_NOTHING_TO_MERGE")); // NOI18N
                         logger.outputInRed( NbBundle.getMessage(MergeAction.class, "MSG_MERGE_DONE")); // NOI18N
                         logger.output(""); // NOI18N
-                        JOptionPane.showMessageDialog(null,
+                        JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                             NbBundle.getMessage(MergeAction.class,"MSG_NOTHING_TO_MERGE"),// NOI18N
                             NbBundle.getMessage(MergeAction.class,"MSG_MERGE_TITLE"),// NOI18N
                             JOptionPane.INFORMATION_MESSAGE);
@@ -163,7 +164,7 @@ public class MergeAction extends ContextAction {
                 if (interactive) {
                     logger.outputInRed(NbBundle.getMessage(MergeAction.class,
                             "MSG_MERGE_FAILED")); // NOI18N
-                    JOptionPane.showMessageDialog(null,
+                    JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                             NbBundle.getMessage(MergeAction.class, "MSG_MERGE_UNCOMMITTED"), // NOI18N
                             NbBundle.getMessage(MergeAction.class, "MSG_MERGE_TITLE"), // NOI18N
                             JOptionPane.WARNING_MESSAGE);
@@ -202,7 +203,7 @@ public class MergeAction extends ContextAction {
             if (HgCommand.isMergeUnavailableMsg(line)) {
                 bMergeFailed = true;
                 if (interactive) {
-                    JOptionPane.showMessageDialog(null,
+                    JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                             NbBundle.getMessage(MergeAction.class, "MSG_MERGE_UNAVAILABLE"), // NOI18N
                             NbBundle.getMessage(MergeAction.class, "MSG_MERGE_TITLE"), // NOI18N
                             JOptionPane.WARNING_MESSAGE);
@@ -252,7 +253,7 @@ public class MergeAction extends ContextAction {
             return;
         }
         Action a = logger.getOpenOutputAction();
-        if (warnInDialog && a != null && JOptionPane.showConfirmDialog(null, NbBundle.getMessage(MergeAction.class, "MSG_MERGE_NEEDED_BRANCHES"), //NOI18N
+        if (warnInDialog && a != null && JOptionPane.showConfirmDialog(Utilities.findDialogParent(), NbBundle.getMessage(MergeAction.class, "MSG_MERGE_NEEDED_BRANCHES"), //NOI18N
                 NbBundle.getMessage(MergeAction.class, "TITLE_MERGE_NEEDED_BRANCHES"), //NOI18N
                 JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
             a.actionPerformed(new ActionEvent(MergeAction.class, ActionEvent.ACTION_PERFORMED, null));
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java
index 2abd2dac83..bc2b9c6737 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/properties/HgProperties.java
@@ -33,6 +33,7 @@ import org.netbeans.modules.mercurial.HgModuleConfig;
 import org.netbeans.modules.mercurial.util.HgRepositoryContextCache;
 import org.openide.util.NbBundle;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 
 /**
  *
@@ -127,7 +128,7 @@ public class HgProperties implements ListSelectionListener {
                             if (bPropChanged && hgPropertyValue.trim().length() >= 0) {
                                 if (hgPropertyName.equals(HGPROPNAME_USERNAME) &&
                                         !HgModuleConfig.getDefault().isUserNameValid(hgPropertyValue)) {
-                                    JOptionPane.showMessageDialog(null,
+                                    JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                                             NbBundle.getMessage(HgProperties.class, "MSG_WARN_USER_NAME_TEXT"), // NOI18N
                                             NbBundle.getMessage(HgProperties.class, "MSG_WARN_FIELD_TITLE"), // NOI18N
                                             JOptionPane.WARNING_MESSAGE);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java
index bb008f48fd..0b52944854 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/pull/PullAction.java
@@ -69,6 +69,7 @@ import org.openide.awt.Mnemonics;
 import org.openide.filesystems.FileUtil;
 import org.openide.nodes.AbstractNode;
 import org.openide.nodes.Children;
+import org.openide.util.Utilities;
 import org.openide.util.actions.SystemAction;
 import org.openide.util.lookup.Lookups;
 
@@ -193,7 +194,7 @@ public class PullAction extends ContextAction {
         if (listIncomingAndLocalMod.size() > 0) {
             logger.outputInRed(NbBundle.getMessage(PullAction.class, "MSG_PULL_OVERWRITE_LOCAL")); // NOI18N
             logger.output(listIncomingAndLocalMod);
-            int response = JOptionPane.showOptionDialog(null, 
+            int response = JOptionPane.showOptionDialog(Utilities.findDialogParent(), 
                     NbBundle.getMessage(bundleLocation, query), NbBundle.getMessage(bundleLocation, title), 
                     JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
 
@@ -392,7 +393,7 @@ public class PullAction extends ContextAction {
             for (Map.Entry<File, FileInformation> e : statuses.entrySet()) {
                 FileInformation info = e.getValue();
                 if ((info.getStatus() & interestingStatus) != 0) {
-                    confirmed = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, 
+                    confirmed = JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Utilities.findDialogParent(), 
                             Bundle.MSG_PullAction_localModifications_text(),
                             Bundle.LBL_PullAction_localModifications_title(), 
                             JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java
index 9b8b48e960..ed0541ce08 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/push/PushAction.java
@@ -54,6 +54,7 @@ import static org.netbeans.modules.mercurial.util.HgUtils.isNullOrEmpty;
 import org.openide.awt.ActionID;
 import org.openide.awt.ActionRegistration;
 import org.openide.filesystems.FileUtil;
+import org.openide.util.Utilities;
 
 /**
  * Push action for mercurial:
@@ -281,7 +282,7 @@ public class PushAction extends ContextAction {
                         logger, showSaveCredsOption);
                 String newBranches = failedNewBranch(list);
                 if (newBranches != null) {
-                    if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(null, 
+                    if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(Utilities.findDialogParent(), 
                             Bundle.MSG_PushAction_questionPushNewBranches(newBranches),
                             NbBundle.getMessage(PushAction.class, "MSG_PUSH_ERROR_TITLE"), //NOI18N
                             JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)) {
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/queues/FailedPatchResolver.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/queues/FailedPatchResolver.java
index 4ec7c6b178..6a4a5bc245 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/queues/FailedPatchResolver.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/queues/FailedPatchResolver.java
@@ -29,6 +29,7 @@ import org.netbeans.modules.mercurial.OutputLogger;
 import org.netbeans.modules.mercurial.util.HgUtils;
 import org.netbeans.modules.versioning.util.Utils;
 import org.openide.util.NbBundle;
+import org.openide.util.Utilities;
 
 /**
  *
@@ -92,7 +93,7 @@ class FailedPatchResolver {
     void resolveFailure () {
         if (isFailure()) {
             HgUtils.openOutput(logger);
-            if (JOptionPane.showConfirmDialog(null, NbBundle.getMessage(FailedPatchResolver.class, "MSG_FailedPatchResolver_patchApplyFailed", failedPatch), //NOI18N
+            if (JOptionPane.showConfirmDialog(Utilities.findDialogParent(), NbBundle.getMessage(FailedPatchResolver.class, "MSG_FailedPatchResolver_patchApplyFailed", failedPatch), //NOI18N
                     NbBundle.getMessage(FailedPatchResolver.class, "LBL_FailedPatchResolver_patchApplyFailed"), //NOI18N
                     JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
                 for (Map.Entry<File, File> e : rejects.entrySet()) {
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/rollback/RollbackAction.java b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/rollback/RollbackAction.java
index a3868b6b40..4dd2c2ea67 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/ui/rollback/RollbackAction.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/ui/rollback/RollbackAction.java
@@ -39,6 +39,7 @@ import org.openide.util.RequestProcessor;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.nodes.Node;
+import org.openide.util.Utilities;
 
 /**
  * Pull action for mercurial: 
@@ -122,7 +123,7 @@ public class RollbackAction extends ContextAction {
                                 Mercurial.getInstance().historyChanged(root);
                                 Mercurial.getInstance().changesetChanged(root);
                             } else {
-                                JOptionPane.showMessageDialog(null,
+                                JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                                         NbBundle.getMessage(RollbackAction.class,"MSG_ROLLBACK_MESSAGE_NOHISTORY") ,  // NOI18N
                                         NbBundle.getMessage(RollbackAction.class,"MSG_ROLLBACK_MESSAGE"), // NOI18N
                                         JOptionPane.INFORMATION_MESSAGE,null);
diff --git a/ide/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java b/ide/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java
index 6acf9732ec..e7199d23e1 100644
--- a/ide/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java
+++ b/ide/mercurial/src/org/netbeans/modules/mercurial/util/HgUtils.java
@@ -259,7 +259,7 @@ public class HgUtils {
      * @return boolean true - answered Yes, false - answered No
      */
     public static boolean confirmDialog(Class bundleLocation, String title, String query) {
-        int response = JOptionPane.showOptionDialog(null, NbBundle.getMessage(bundleLocation, query), NbBundle.getMessage(bundleLocation, title), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
+        int response = JOptionPane.showOptionDialog(Utilities.findDialogParent(), NbBundle.getMessage(bundleLocation, query), NbBundle.getMessage(bundleLocation, title), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
 
         if (response == JOptionPane.YES_OPTION) {
             return true;
@@ -276,7 +276,7 @@ public class HgUtils {
      * @param warning to display to the user
      */
      public static void warningDialog(Class bundleLocation, String title, String warning) {
-        JOptionPane.showMessageDialog(null,
+        JOptionPane.showMessageDialog(Utilities.findDialogParent(),
                 NbBundle.getMessage(bundleLocation,warning),
                 NbBundle.getMessage(bundleLocation,title),
                 JOptionPane.WARNING_MESSAGE);
diff --git a/ide/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java b/ide/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java
index 3ca079ee41..cc520e940a 100644
--- a/ide/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java
+++ b/ide/project.ant/src/org/netbeans/modules/project/ant/ProjectLibraryProvider.java
@@ -95,6 +95,7 @@ import org.openide.util.MutexException;
 import org.openide.util.NbBundle;
 import org.openide.util.NbCollections;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 import org.openide.util.WeakListeners;
 import org.openide.util.lookup.ServiceProvider;
 import org.openide.xml.XMLUtil;
@@ -191,7 +192,7 @@ public class ProjectLibraryProvider implements ArealLibraryProvider<ProjectLibra
         };
         jfc.setFileFilter(filter);
         FileUtil.preventFileChooserSymlinkTraversal(jfc, null); // XXX remember last-selected dir
-        while (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+        while (jfc.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
             File f = jfc.getSelectedFile();
             if (filter.accept(f)) {
                 return new ProjectLibraryArea(f);
diff --git a/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/DictionaryInstallerPanel.java b/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/DictionaryInstallerPanel.java
index aeeff58769..13ab6417be 100644
--- a/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/DictionaryInstallerPanel.java
+++ b/ide/spellchecker/src/org/netbeans/modules/spellchecker/options/DictionaryInstallerPanel.java
@@ -176,7 +176,7 @@ public class DictionaryInstallerPanel extends javax.swing.JPanel {
 
     private void bBrowseActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBrowseActionPerformed
         JFileChooser filechooser = new JFileChooser (tDictionary.getText ());
-        int ret = filechooser.showOpenDialog (null);
+        int ret = filechooser.showOpenDialog (org.openide.util.Utilities.findDialogParent());
         if (ret == JFileChooser.APPROVE_OPTION)
             tDictionary.setText (filechooser.getSelectedFile ().getAbsolutePath ());
     }//GEN-LAST:event_bBrowseActionPerformed
diff --git a/ide/subversion/src/org/netbeans/modules/subversion/ModuleLifecycleManager.java b/ide/subversion/src/org/netbeans/modules/subversion/ModuleLifecycleManager.java
index 38a30f57b6..f87a41b835 100644
--- a/ide/subversion/src/org/netbeans/modules/subversion/ModuleLifecycleManager.java
+++ b/ide/subversion/src/org/netbeans/modules/subversion/ModuleLifecycleManager.java
@@ -37,6 +37,7 @@ import java.io.IOException;
 import java.io.ByteArrayInputStream;
 import java.util.logging.Level;
 import org.openide.filesystems.FileUtil;
+import org.openide.util.Utilities;
 
 /**
  * Handles module events distributed by NetBeans module
@@ -93,7 +94,7 @@ public final class ModuleLifecycleManager extends ModuleInstall implements Error
                             }
                         }
                         if (!notified) {
-                            JOptionPane.showMessageDialog(null, 
+                            JOptionPane.showMessageDialog(Utilities.findDialogParent(), 
                                                           NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning"),  // NOI18N
                                                           NbBundle.getBundle(ModuleLifecycleManager.class).getString("MSG_Install_Warning_Title"),  // NOI18N
                                                           JOptionPane.WARNING_MESSAGE);
diff --git a/ide/subversion/src/org/netbeans/modules/subversion/ui/update/ResolveConflictsExecutor.java b/ide/subversion/src/org/netbeans/modules/subversion/ui/update/ResolveConflictsExecutor.java
index 8105f0133a..ac412c6d6e 100644
--- a/ide/subversion/src/org/netbeans/modules/subversion/ui/update/ResolveConflictsExecutor.java
+++ b/ide/subversion/src/org/netbeans/modules/subversion/ui/update/ResolveConflictsExecutor.java
@@ -106,7 +106,7 @@ public class ResolveConflictsExecutor extends SvnProgressSupport {
             });
         } catch (IOException ioex) {
             if (NESTED_CONFLICT.equals(ioex.getMessage())) {
-                JOptionPane.showMessageDialog(null, NbBundle.getMessage(ResolveConflictsExecutor.class, "MSG_NestedConflicts"),
+                JOptionPane.showMessageDialog(Utilities.findDialogParent(), NbBundle.getMessage(ResolveConflictsExecutor.class, "MSG_NestedConflicts"),
                                               NbBundle.getMessage(ResolveConflictsExecutor.class, "MSG_NestedConflicts_Title"),
                                               JOptionPane.WARNING_MESSAGE);
                 Utils.openFile(file);
diff --git a/ide/subversion/src/org/netbeans/modules/subversion/ui/wcadmin/UpgradeAction.java b/ide/subversion/src/org/netbeans/modules/subversion/ui/wcadmin/UpgradeAction.java
index 887f2682a9..278611c9bb 100644
--- a/ide/subversion/src/org/netbeans/modules/subversion/ui/wcadmin/UpgradeAction.java
+++ b/ide/subversion/src/org/netbeans/modules/subversion/ui/wcadmin/UpgradeAction.java
@@ -43,6 +43,7 @@ import org.openide.awt.StatusDisplayer;
 import org.openide.nodes.Node;
 import org.openide.util.NbBundle;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 import org.tigris.subversion.svnclientadapter.SVNClientException;
 
 /**
@@ -184,7 +185,7 @@ public class UpgradeAction extends ContextAction {
     }
 
     private boolean forceUpgrade (String path) {
-        return JOptionPane.showConfirmDialog(null, NbBundle.getMessage(UpgradeAction.class, "MSG_Upgrade_forceUpgrade", path), //NOI18N
+        return JOptionPane.showConfirmDialog(Utilities.findDialogParent(), NbBundle.getMessage(UpgradeAction.class, "MSG_Upgrade_forceUpgrade", path), //NOI18N
                 NbBundle.getMessage(UpgradeAction.class, "LBL_Upgrade_title", path), //NOI18N
                 JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION;
     }
diff --git a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/SourceJavadocAttacherUtil.java b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/SourceJavadocAttacherUtil.java
index 897c170485..0425e36e9a 100644
--- a/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/SourceJavadocAttacherUtil.java
+++ b/java/java.j2seplatform/src/org/netbeans/modules/java/j2seplatform/queries/SourceJavadocAttacherUtil.java
@@ -304,7 +304,7 @@ public final class SourceJavadocAttacherUtil {
                 if (currentFolder[0] != null) {
                     chooser.setCurrentDirectory(currentFolder[0]);
                 }
-                if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+                if (chooser.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
                     currentFolder[0] = chooser.getCurrentDirectory();
                     final File[] files = filter(chooser.getSelectedFiles(), filter);
                     final List<String> result = new ArrayList<String>(files.length);
diff --git a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/ProjectProblemsProviders.java b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/ProjectProblemsProviders.java
index 48998f27ef..21f9c7268a 100644
--- a/java/java.project.ui/src/org/netbeans/modules/java/project/ui/ProjectProblemsProviders.java
+++ b/java/java.project.ui/src/org/netbeans/modules/java/project/ui/ProjectProblemsProviders.java
@@ -886,7 +886,7 @@ public class ProjectProblemsProviders {
             if (lastSelectedFile != null) {
                 chooser.setSelectedFile(lastSelectedFile);
             }
-            int option = chooser.showOpenDialog(null);
+            int option = chooser.showOpenDialog(Utilities.findDialogParent());
             if (option == JFileChooser.APPROVE_OPTION) {
                 updateReference(chooser.getSelectedFile());
                 lastSelectedFile = chooser.getSelectedFile();
@@ -928,7 +928,7 @@ public class ProjectProblemsProviders {
             if (lastSelectedFile != null) {
                 chooser.setSelectedFile(lastSelectedFile);
             }
-            int option = chooser.showOpenDialog(null);
+            int option = chooser.showOpenDialog(Utilities.findDialogParent());
             if (option == JFileChooser.APPROVE_OPTION) {
                 updateReference(chooser.getSelectedFile());
                 lastSelectedFile = chooser.getSelectedFile();
diff --git a/java/maven/src/org/netbeans/modules/maven/nodes/ModulesNode.java b/java/maven/src/org/netbeans/modules/maven/nodes/ModulesNode.java
index 5c84f8d66c..a817cdeaab 100644
--- a/java/maven/src/org/netbeans/modules/maven/nodes/ModulesNode.java
+++ b/java/maven/src/org/netbeans/modules/maven/nodes/ModulesNode.java
@@ -63,6 +63,7 @@ import org.openide.util.ImageUtilities;
 import org.openide.util.Lookup;
 import org.openide.util.NbBundle.Messages;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 import org.openide.util.WeakListeners;
 
 /**
@@ -297,7 +298,7 @@ public class ModulesNode extends AbstractNode {
             JFileChooser c = ProjectChooser.projectChooser();
             File basedir = FileUtil.toFile(proj.getProjectDirectory());
             c.setCurrentDirectory(basedir);
-            if (c.showOpenDialog(null) != JFileChooser.APPROVE_OPTION) {
+            if (c.showOpenDialog(Utilities.findDialogParent()) != JFileChooser.APPROVE_OPTION) {
                 return;
             }
             final List<String> mods = new ArrayList<String>();
diff --git a/javafx/maven.htmlui/nbproject/project.xml b/javafx/maven.htmlui/nbproject/project.xml
index c53fa16608..befe061380 100644
--- a/javafx/maven.htmlui/nbproject/project.xml
+++ b/javafx/maven.htmlui/nbproject/project.xml
@@ -99,6 +99,14 @@
                         <specification-version>8.34</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.openide.util.ui</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <specification-version>9.26</specification-version>
+                    </run-dependency>
+                </dependency>
             </module-dependencies>
             <test-dependencies>
                 <test-type>
diff --git a/javafx/maven.htmlui/src/org/netbeans/modules/maven/htmlui/DukeScriptWizard.java b/javafx/maven.htmlui/src/org/netbeans/modules/maven/htmlui/DukeScriptWizard.java
index e8d0c4b671..e0a92789e1 100644
--- a/javafx/maven.htmlui/src/org/netbeans/modules/maven/htmlui/DukeScriptWizard.java
+++ b/javafx/maven.htmlui/src/org/netbeans/modules/maven/htmlui/DukeScriptWizard.java
@@ -34,6 +34,7 @@ import net.java.html.json.OnPropertyChange;
 import net.java.html.json.OnReceive;
 import org.openide.filesystems.FileChooserBuilder;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 
 @Model(className = "WizardData", properties = {
     @Property(name = "current", type = String.class),
@@ -247,7 +248,7 @@ public class DukeScriptWizard {
                     b.setDefaultWorkingDirectory(new File(data.getAndroidSdkPath()));
                 }
                 JFileChooser fc = b.createFileChooser();
-                int res = fc.showOpenDialog(null);
+                int res = fc.showOpenDialog(Utilities.findDialogParent());
                 if (res == JFileChooser.APPROVE_OPTION) {
                     data.setAndroidSdkPath(fc.getSelectedFile().getPath());
                     MavenUtilities.getDefault().writeAndroidSdkPath(fc.getSelectedFile().getPath());
@@ -322,7 +323,7 @@ public class DukeScriptWizard {
                 JFileChooser fc = b.createFileChooser();
                 File f = new File(System.getProperty("netbeans.home"));
                 fc.setCurrentDirectory(f);
-                int res = fc.showOpenDialog(null);
+                int res = fc.showOpenDialog(Utilities.findDialogParent());
                 if (res == JFileChooser.APPROVE_OPTION) {
                     MavenUtilities.getDefault().writeNetBeansInstallation(f.getParent());
                     if (MavenUtilities.getDefault().readNetBeansInstallation() != null) {
diff --git a/platform/openide.filesystems.nb/src/org/openide/filesystems/FileChooserBuilder.java b/platform/openide.filesystems.nb/src/org/openide/filesystems/FileChooserBuilder.java
index fe6f924037..596d89fbbd 100644
--- a/platform/openide.filesystems.nb/src/org/openide/filesystems/FileChooserBuilder.java
+++ b/platform/openide.filesystems.nb/src/org/openide/filesystems/FileChooserBuilder.java
@@ -22,7 +22,6 @@ import java.awt.Component;
 import java.awt.FileDialog;
 import java.awt.Frame;
 import java.awt.HeadlessException;
-import java.awt.KeyboardFocusManager;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -288,23 +287,6 @@ public class FileChooserBuilder {
         return this;
     }
 
-    /**
-     * Tries to find an appropriate component to parent the file chooser to
-     * when showing a dialog.
-     * @return this
-     */
-    private 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];
-        }
-        return parent;
-    }
-
     /**
      * Show an open dialog that allows multiple selection.
      * @return An array of files, or null if the user cancelled the dialog
@@ -312,7 +294,7 @@ public class FileChooserBuilder {
     public File[] showMultiOpenDialog() {
         JFileChooser chooser = createFileChooser();
         chooser.setMultiSelectionEnabled(true);
-        int result = chooser.showOpenDialog(findDialogParent());
+        int result = chooser.showOpenDialog(Utilities.findDialogParent());
         if (JFileChooser.APPROVE_OPTION == result) {
             File[] files = chooser.getSelectedFiles();
             return files == null ? new File[0] : files;
@@ -336,7 +318,7 @@ public class FileChooserBuilder {
             }
         }
         chooser.setMultiSelectionEnabled(false);
-        int dlgResult = chooser.showOpenDialog(findDialogParent());
+        int dlgResult = chooser.showOpenDialog(Utilities.findDialogParent());
         if (JFileChooser.APPROVE_OPTION == dlgResult) {
             File result = chooser.getSelectedFile();
             if (result != null && !result.exists()) {
@@ -363,7 +345,7 @@ public class FileChooserBuilder {
                 return showFileDialog( fileDialog, FileDialog.SAVE );
             }
         }
-        int result = chooser.showSaveDialog(findDialogParent());
+        int result = chooser.showSaveDialog(Utilities.findDialogParent());
         if (JFileChooser.APPROVE_OPTION == result) {
             return chooser.getSelectedFile();
         } else {
@@ -434,7 +416,7 @@ public class FileChooserBuilder {
             return null;
         if( dirsOnly && !BaseUtilities.isMac() )
             return null;
-        Component parentComponent = findDialogParent();
+        Component parentComponent = Utilities.findDialogParent();
         Frame parentFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, parentComponent);
         FileDialog fileDialog = new FileDialog(parentFrame);
         if (title != null) {
diff --git a/platform/openide.util.ui/apichanges.xml b/platform/openide.util.ui/apichanges.xml
index d2fcd96f38..c6c18b20d0 100644
--- a/platform/openide.util.ui/apichanges.xml
+++ b/platform/openide.util.ui/apichanges.xml
@@ -27,6 +27,22 @@
     <apidef name="actions">Actions API</apidef>
 </apidefs>
 <changes>
+    <change id="findDialogParent">
+         <api name="util"/>
+         <summary>static method Utilities.findDialogParent added</summary>
+         <version major="9" minor="26"/>
+         <date day="15" month="10" year="2022"/>
+         <author login="errael"/>
+         <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/>
+         <description>
+             <p>
+                 Added <code>findDialogParent</code> to provide a parent component for standard swing dialog displayers
+                 such as <code>JOptionPane</code> and <code>JFileChooser</code>.
+                 This method first checks <code>KeyboardFocusManager</code>, then uses an active frame.
+             </p>
+         </description>
+         <class package="org.openide.util" name="Utilities"/>
+    </change>
     <change id="propertyURL">
       <api name="util"/>
       <summary>Declaration of long-used URL image property</summary>  
diff --git a/platform/openide.util.ui/src/org/openide/util/Utilities.java b/platform/openide.util.ui/src/org/openide/util/Utilities.java
index 2f513f2bfa..3310e33657 100644
--- a/platform/openide.util.ui/src/org/openide/util/Utilities.java
+++ b/platform/openide.util.ui/src/org/openide/util/Utilities.java
@@ -1325,6 +1325,32 @@ public final class Utilities {
         );
     }
 
+    /**
+     * 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];
+        }
+        return parent;
+    }
+
     /** @return size of the screen. The size is modified for Windows OS
      * - some points are subtracted to reflect a presence of the taskbar
      *
diff --git a/platform/templates/src/org/netbeans/modules/templates/ui/TemplatesPanel.java b/platform/templates/src/org/netbeans/modules/templates/ui/TemplatesPanel.java
index 8e5ebf8c14..6c24f14ec5 100644
--- a/platform/templates/src/org/netbeans/modules/templates/ui/TemplatesPanel.java
+++ b/platform/templates/src/org/netbeans/modules/templates/ui/TemplatesPanel.java
@@ -93,6 +93,7 @@ import org.openide.util.Lookup;
 import org.openide.util.NbBundle;
 import org.openide.util.NbBundle.Messages;
 import org.openide.util.RequestProcessor;
+import org.openide.util.Utilities;
 import org.openide.util.actions.NodeAction;
 import org.openide.util.actions.SystemAction;
 import org.openide.util.datatransfer.PasteType;
@@ -1262,7 +1263,7 @@ public class TemplatesPanel extends TopComponent implements ExplorerManager.Prov
         chooser.setApproveButtonText(BTN_TemplatesPanel_JFileChooser_AddButtonName());
         chooser.setFileHidingEnabled (false);
         chooser.setMultiSelectionEnabled (false);
-        int result = chooser.showOpenDialog (null);
+        int result = chooser.showOpenDialog (Utilities.findDialogParent());
         if (JFileChooser.APPROVE_OPTION == result) {
             final File f = chooser.getSelectedFile ();
             assert f != null;
diff --git a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LoadGeneratorCustomizer.java b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LoadGeneratorCustomizer.java
index e5d39b3d29..d4e0a0f4da 100644
--- a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LoadGeneratorCustomizer.java
+++ b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LoadGeneratorCustomizer.java
@@ -59,6 +59,7 @@ import javax.swing.event.DocumentListener;
 import javax.swing.filechooser.FileFilter;
 import org.netbeans.lib.profiler.ui.UIUtils;
 import org.netbeans.modules.profiler.api.ProjectUtilities;
+import org.openide.util.Utilities;
 
 
 /**
@@ -194,7 +195,7 @@ public class LoadGeneratorCustomizer extends ValidityAwarePanel implements Actio
                 fileChooser.setCurrentDirectory(FileUtil.toFile(ProjectUtilities.getProjectDirectory(project)));
             }
 
-            if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+            if (fileChooser.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
                 scriptTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
             }
         }
diff --git a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LocationCustomizer.java b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LocationCustomizer.java
index e1c1414d33..0070310837 100644
--- a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LocationCustomizer.java
+++ b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/LocationCustomizer.java
@@ -58,6 +58,7 @@ import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.filechooser.FileFilter;
+import org.openide.util.Utilities;
 
 
 /**
@@ -177,7 +178,7 @@ public class LocationCustomizer extends ValidityAwarePanel implements ActionList
             JFileChooser fileChooser = getFileChooser();
             fileChooser.setCurrentDirectory(new File(fileTextField.getText()));
 
-            if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+            if (fileChooser.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
                 fileTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
             }
         } else if (e.getSource() == fromEditorButton) {
diff --git a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/SnapshotCustomizer.java b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/SnapshotCustomizer.java
index d0dbd8c0a6..59f1b4e3f9 100644
--- a/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/SnapshotCustomizer.java
+++ b/profiler/profiler.ppoints/src/org/netbeans/modules/profiler/ppoints/ui/SnapshotCustomizer.java
@@ -45,6 +45,7 @@ import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
+import org.openide.util.Utilities;
 
 
 /**
@@ -102,7 +103,7 @@ public class SnapshotCustomizer extends ValidityAwarePanel implements ActionList
             JFileChooser fileChooser = getFileChooser();
             fileChooser.setCurrentDirectory(new File(saveToFileField.getText()).getParentFile());
 
-            if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
+            if (fileChooser.showOpenDialog(Utilities.findDialogParent()) == JFileChooser.APPROVE_OPTION) {
                 saveToFileField.setText(fileChooser.getSelectedFile().getAbsolutePath());
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists