Skip to content

Commit 831bf83

Browse files
committed
8295804: javax/swing/JFileChooser/JFileChooserSetLocationTest.java failed with "setLocation() is not working properly"
Backport-of: 05dad67cc23fb49627fabfb306acee247ff67aef
1 parent 665dcff commit 831bf83

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

test/jdk/javax/swing/JFileChooser/JFileChooserSetLocationTest.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
@@ -29,6 +29,7 @@
2929
import java.awt.Point;
3030
import java.awt.Rectangle;
3131
import java.awt.Robot;
32+
import java.awt.Toolkit;
3233
import java.awt.event.ActionListener;
3334
import java.awt.event.InputEvent;
3435
import 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

Comments
 (0)