@@ -137,6 +137,20 @@ public SystemClipboard getSystemClipboard() {
137137
138138 @ Override
139139 public File chooseFile (final File file , final String style ) {
140+ return chooseFile ((Component )null , file , style );
141+ }
142+
143+ /**
144+ * Like {@link #chooseFile(File, String)}, but the dialog is shown relative
145+ * to the given component.
146+ *
147+ * @param owner The component to center the dialog on. If {@code null}, the
148+ * application frame is used.
149+ */
150+ public File chooseFile (final Component owner , final File file ,
151+ final String style )
152+ {
153+ final Component parent = owner != null ? owner : appFrame ;
140154 final File [] result = new File [1 ];
141155 try {
142156 // NB: We show the JFileChooser on the EDT because otherwise there could
@@ -148,10 +162,10 @@ public File chooseFile(final File file, final String style) {
148162 }
149163 final int rval ;
150164 if (FileWidget .SAVE_STYLE .equals (style )) {
151- rval = chooser .showSaveDialog (appFrame );
165+ rval = chooser .showSaveDialog (parent );
152166 }
153167 else { // default behavior
154- rval = chooser .showOpenDialog (appFrame );
168+ rval = chooser .showOpenDialog (parent );
155169 }
156170 if (rval == JFileChooser .APPROVE_OPTION ) {
157171 result [0 ] = chooser .getSelectedFile ();
@@ -166,6 +180,20 @@ public File chooseFile(final File file, final String style) {
166180
167181 @ Override
168182 public File [] chooseFiles (final File parent , final File [] files , final FileFilter filter , final String style ) {
183+ return chooseFiles (null , parent , files , filter , style );
184+ }
185+
186+ /**
187+ * Like {@link #chooseFiles(File, File[], FileFilter, String)}, but the
188+ * dialog is shown relative to the given component.
189+ *
190+ * @param owner The component to center the dialog on. If {@code null}, the
191+ * application frame is used.
192+ */
193+ public File [] chooseFiles (final Component owner , final File parent ,
194+ final File [] files , final FileFilter filter , final String style )
195+ {
196+ final Component dialogParent = owner != null ? owner : appFrame ;
169197 final File [][] result = new File [1 ][];
170198 try {
171199 // NB: We show the JFileChooser on the EDT because otherwise there could
@@ -202,7 +230,7 @@ public boolean accept(File f) {
202230 };
203231 chooser .setFileFilter (fileFilter );
204232 }
205- int rval = chooser .showOpenDialog (appFrame );
233+ int rval = chooser .showOpenDialog (dialogParent );
206234 if (rval == JFileChooser .APPROVE_OPTION ) {
207235 result [0 ] = chooser .getSelectedFiles ();
208236 }
0 commit comments