11/*
2- * Copyright (c) 2015, 2022 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2024 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2929import java .awt .Point ;
3030import java .awt .Rectangle ;
3131import java .awt .Robot ;
32+ import java .awt .Toolkit ;
3233import java .awt .event .ActionListener ;
3334import java .awt .event .InputEvent ;
3435import java .awt .event .KeyEvent ;
@@ -209,7 +210,11 @@ private static void hitKeys(int... keys) {
209210 }
210211
211212 public static void createUI () {
212- frame = new JFrame ();
213+ Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
214+
215+ int xPos = (int ) screenSize .getWidth () / 2 ;
216+ int yPos = (int ) screenSize .getHeight () / 2 ;
217+ frame = new JFrame ("FileChooser set location test" );
213218 panel = new JPanel ();
214219 btn = new JButton (SHOW_DIALOG_OUTSIDE_THE_PANEL );
215220 btn1 = new JButton (SHOW_DIALOG_OVER_THE_PANEL );
@@ -238,6 +243,7 @@ public static void createUI() {
238243 frame .setLocationRelativeTo (null );
239244 frame .setDefaultCloseOperation (JFrame .DISPOSE_ON_CLOSE );
240245 frame .pack ();
246+ frame .setLocation (xPos , yPos - 200 );
241247 frame .setVisible (true );
242248 }
243249
@@ -280,7 +286,6 @@ protected JDialog createDialog(Component parent)
280286 System .out .println (
281287 "createDialog and set location to (" + x + ", " + y + ")" );
282288 dialog .setLocation (x , y );
283-
284289 return dialog ;
285290 }
286291
@@ -289,5 +294,4 @@ public Point getDialogLocation() {
289294 }
290295
291296 }
292-
293297}
0 commit comments