Skip to content

Commit 85453b6

Browse files
author
Sonia Zaldana Calles
committed
8315882: Open some swing tests 2
Backport-of: d2d7d9a8b7c68865553dcbb4d660bbb06fde3974
1 parent e1b5f3c commit 85453b6

File tree

3 files changed

+228
-0
lines changed

3 files changed

+228
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4688907
27+
* @summary ScrollPaneLayout.minimumLayoutSize incorrectly compares hsbPolicy
28+
*/
29+
30+
import java.awt.Dimension;
31+
import javax.swing.JScrollPane;
32+
33+
public class bug4688907 {
34+
public static void main(String[] args) throws Exception {
35+
JScrollPane sp = new JScrollPane();
36+
Dimension d1 = sp.getMinimumSize();
37+
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
38+
Dimension d2 = sp.getMinimumSize();
39+
if (d1.height == d2.height) {
40+
throw new RuntimeException("The scrollbar minimum size doesn't take " +
41+
"into account horizontal scrollbar policy");
42+
}
43+
}
44+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4756178
27+
* @summary SpringLayout:applyDefaults() discards size information when right-aligning.
28+
* @key headful
29+
*/
30+
31+
import java.awt.Dimension;
32+
import java.awt.Robot;
33+
import javax.swing.JButton;
34+
import javax.swing.JFrame;
35+
import javax.swing.JPanel;
36+
import javax.swing.Spring;
37+
import javax.swing.SpringLayout;
38+
import javax.swing.SwingUtilities;
39+
40+
public class bug4756178 {
41+
static JFrame fr;
42+
static JButton bt;
43+
static volatile Dimension buttonPreferredSize;
44+
static volatile Dimension actualSize;
45+
46+
public static void main(String[] args) throws Exception {
47+
try {
48+
SwingUtilities.invokeAndWait(() -> {
49+
fr = new JFrame("bug4756178");
50+
JPanel p = (JPanel) fr.getContentPane();
51+
SpringLayout layout = new SpringLayout();
52+
p.setLayout(layout);
53+
54+
SpringLayout.Constraints cc = new SpringLayout.Constraints();
55+
cc.setConstraint("East",
56+
Spring.sum(Spring.constant(-20),
57+
layout.getConstraint("East", p)));
58+
cc.setConstraint("South",
59+
Spring.sum(Spring.constant(-20),
60+
layout.getConstraint("South", p)));
61+
62+
bt = new JButton();
63+
64+
buttonPreferredSize = new Dimension(20, 20);
65+
bt.setPreferredSize(buttonPreferredSize);
66+
p.add(bt, cc);
67+
68+
fr.setSize(200, 200);
69+
fr.setLocationRelativeTo(null);
70+
fr.setVisible(true);
71+
});
72+
73+
Robot robot = new Robot();
74+
robot.waitForIdle();
75+
robot.delay(1000);
76+
77+
SwingUtilities.invokeAndWait(() -> {
78+
actualSize = bt.getSize();
79+
});
80+
81+
if (!buttonPreferredSize.equals(actualSize)) {
82+
throw new RuntimeException("Button size is " + actualSize +
83+
", should be " + buttonPreferredSize);
84+
}
85+
} finally {
86+
SwingUtilities.invokeAndWait(() -> {
87+
if (fr != null) {
88+
fr.dispose();
89+
}
90+
});
91+
}
92+
}
93+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 4803649
27+
* @summary setWidth() doesn't work on the container in a SpringLayout
28+
* @key headful
29+
*/
30+
31+
import java.awt.Dimension;
32+
import java.awt.Robot;
33+
import javax.swing.JFrame;
34+
import javax.swing.JPanel;
35+
import javax.swing.JTextArea;
36+
import javax.swing.Spring;
37+
import javax.swing.SpringLayout;
38+
import javax.swing.SwingUtilities;
39+
40+
public class bug4803649 {
41+
static JFrame fr;
42+
static JPanel panel;
43+
44+
public static void main(String[] args) throws Exception {
45+
try {
46+
SwingUtilities.invokeAndWait(() -> {
47+
fr = new JFrame("bug4803649");
48+
49+
panel = new JPanel();
50+
SpringLayout layout = new SpringLayout();
51+
panel.setLayout(layout);
52+
53+
JTextArea textArea = new JTextArea("asasddsa");
54+
textArea.setPreferredSize(new Dimension(200, 200));
55+
panel.add(textArea);
56+
SpringLayout.Constraints cCons = layout.getConstraints(textArea);
57+
cCons.setX(Spring.constant(10));
58+
cCons.setY(Spring.constant(10));
59+
60+
SpringLayout.Constraints pCons = layout.getConstraints(panel);
61+
pCons.setWidth(Spring.sum(Spring.constant(10),
62+
cCons.getConstraint("East")));
63+
pCons.setHeight(Spring.sum(Spring.constant(10),
64+
cCons.getConstraint("South")));
65+
66+
fr.getContentPane().add(panel);
67+
68+
fr.setLocationRelativeTo(null);
69+
fr.pack();
70+
fr.setVisible(true);
71+
});
72+
73+
Robot r = new Robot();
74+
r.waitForIdle();
75+
r.delay(1000);
76+
77+
SwingUtilities.invokeAndWait(() -> {
78+
Dimension d = panel.getSize();
79+
if (d.width < 220 || d.height < 220) {
80+
throw new RuntimeException("JPanel with the SpringLayout is too small");
81+
}
82+
});
83+
} finally {
84+
SwingUtilities.invokeAndWait(() -> {
85+
if (fr != null) {
86+
fr.dispose();
87+
}
88+
});
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)