Skip to content

Commit 08de2ba

Browse files
committed
8352908: Open source several swing tests batch1
Backport-of: a2dc9c71e47a1cdf70ab351c557a5f1835eb5f4a
1 parent 99c9fc7 commit 08de2ba

File tree

4 files changed

+353
-0
lines changed

4 files changed

+353
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2003, 2025, 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 4749792
27+
* @requires (os.family == "windows")
28+
* @summary Split pane border is not painted properly
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4749792
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Dimension;
36+
37+
import javax.swing.JFrame;
38+
import javax.swing.JPanel;
39+
import javax.swing.JSplitPane;
40+
41+
public class bug4749792 {
42+
static final String INSTRUCTIONS = """
43+
If the right/bottom edges of JSplitPane's border is missing then the
44+
test fails. If it is visible, then the test passes.
45+
""";
46+
47+
static JFrame createUI() {
48+
JFrame frame = new JFrame("JSplitPane Border Test");
49+
frame.setSize(450, 220);
50+
JPanel left = new JPanel();
51+
JPanel right = new JPanel();
52+
left.setPreferredSize(new Dimension(200, 200));
53+
right.setPreferredSize(new Dimension(200, 200));
54+
JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right);
55+
frame.add(sp);
56+
57+
JPanel south = new JPanel();
58+
south.setPreferredSize(new Dimension(20, 20));
59+
frame.add(south, BorderLayout.SOUTH);
60+
61+
JPanel east = new JPanel();
62+
east.setPreferredSize(new Dimension(20, 20));
63+
frame.add(east, BorderLayout.EAST);
64+
65+
return frame;
66+
}
67+
68+
public static void main(String[] args) throws Exception {
69+
PassFailJFrame.builder()
70+
.title("bug4749792 Test Instructions")
71+
.instructions(INSTRUCTIONS)
72+
.columns(40)
73+
.testUI(bug4749792::createUI)
74+
.build()
75+
.awaitAndCheck();
76+
}
77+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (c) 2000, 2025, 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 4188825
27+
* @summary Tests if toolbars return to original location when closed
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4188825
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
35+
import javax.swing.JButton;
36+
import javax.swing.JFrame;
37+
import javax.swing.JToolBar;
38+
39+
public class bug4188825 {
40+
static final String INSTRUCTIONS = """
41+
Drag the toolbar out of frame and close it. If it returns to
42+
the original location, then the test succeeded, otherwise it failed.
43+
""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("bug4188825 Test Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.columns(40)
50+
.testUI(bug4188825::createUI)
51+
.build()
52+
.awaitAndCheck();
53+
}
54+
55+
static JFrame createUI() {
56+
JFrame frame = new JFrame("Toolbar Drag Test");
57+
frame.setLayout(new BorderLayout());
58+
JToolBar tb = new JToolBar();
59+
tb.setOrientation(JToolBar.VERTICAL);
60+
tb.add(new JButton("a"));
61+
tb.add(new JButton("b"));
62+
tb.add(new JButton("c"));
63+
frame.add(tb, BorderLayout.WEST);
64+
JButton l = new JButton("Get me!!!");
65+
l.setSize(200, 200);
66+
frame.add(l);
67+
frame.setSize(200, 200);
68+
return frame;
69+
}
70+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2000, 2025, 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 4251592
27+
* @summary JToolBar should have ability to set custom layout.
28+
* @key headful
29+
* @run main bug4251592
30+
*/
31+
32+
import java.awt.BorderLayout;
33+
import java.awt.GridLayout;
34+
import java.awt.Point;
35+
import java.awt.Robot;
36+
import java.awt.event.InputEvent;
37+
38+
import javax.swing.JButton;
39+
import javax.swing.JFrame;
40+
import javax.swing.JToolBar;
41+
import javax.swing.SwingUtilities;
42+
43+
public class bug4251592 {
44+
private static final int OFFSET = 3;
45+
private static volatile Point loc;
46+
private static JFrame frame;
47+
private static JToolBar toolBar;
48+
private static GridLayout customLayout;
49+
50+
public static void main(String[] args) throws Exception {
51+
Robot robot = new Robot();
52+
robot.setAutoDelay(100);
53+
try {
54+
SwingUtilities.invokeAndWait(() -> {
55+
frame = new JFrame("Toolbar Layout Save Test");
56+
toolBar = new JToolBar();
57+
customLayout = new GridLayout();
58+
frame.setLayout(new BorderLayout());
59+
frame.add(toolBar, BorderLayout.NORTH);
60+
61+
toolBar.setLayout(customLayout);
62+
toolBar.add(new JButton("Button1"));
63+
toolBar.add(new JButton("Button2"));
64+
toolBar.add(new JButton("Button3"));
65+
toolBar.setFloatable(true);
66+
67+
frame.setSize(200, 200);
68+
frame.setLocationRelativeTo(null);
69+
frame.setVisible(true);
70+
});
71+
72+
robot.waitForIdle();
73+
robot.delay(1000);
74+
75+
SwingUtilities.invokeAndWait(() -> loc = toolBar.getLocationOnScreen());
76+
77+
robot.mouseMove(loc.x + OFFSET, loc.y + OFFSET);
78+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
79+
robot.mouseMove(loc.x + OFFSET, loc.y + 50);
80+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
81+
82+
if (toolBar.getLayout() != customLayout) {
83+
throw new RuntimeException("Custom layout not saved...");
84+
}
85+
} finally {
86+
SwingUtilities.invokeAndWait(() -> {
87+
if (frame != null) {
88+
frame.dispose();
89+
}
90+
});
91+
}
92+
}
93+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2004, 2025, 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 5035668
27+
* @summary Test that metal ToolBar border correctly sizes the MetalBumps used
28+
* for the grip
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug5035668
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Color;
36+
import java.awt.ComponentOrientation;
37+
import java.awt.GridLayout;
38+
39+
import javax.swing.JButton;
40+
import javax.swing.JFrame;
41+
import javax.swing.JPanel;
42+
import javax.swing.JToolBar;
43+
import javax.swing.UIManager;
44+
import javax.swing.border.CompoundBorder;
45+
import javax.swing.border.EmptyBorder;
46+
47+
public class bug5035668 {
48+
static final String INSTRUCTIONS = """
49+
This test is for Metal LaF only.
50+
51+
All of them have an empty border around their own border.
52+
If you see that in any toolbar the grip (little dotted strip) overlaps
53+
the empty border press Fail. If you see that grips are completely
54+
inside empty borders press Pass.
55+
""";
56+
57+
public static void main(String[] args) throws Exception {
58+
// Set metal l&f
59+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
60+
PassFailJFrame.builder()
61+
.title("bug4251592 Test Instructions")
62+
.instructions(INSTRUCTIONS)
63+
.columns(40)
64+
.testUI(bug5035668::createUI)
65+
.build()
66+
.awaitAndCheck();
67+
}
68+
69+
static JFrame createUI() {
70+
JFrame frame = new JFrame("Metal JToolBar Border Overlap Test");
71+
frame.setLayout(new BorderLayout());
72+
frame.setBackground(Color.white);
73+
74+
// Horizontal toolbar left-to-right
75+
final JToolBar toolBar = new JToolBar();
76+
toolBar.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10),
77+
toolBar.getBorder()));
78+
toolBar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
79+
toolBar.add(new ToolBarButton(toolBar));
80+
81+
// Horizontal toolbar right-to-left
82+
JToolBar toolBar2 = new JToolBar();
83+
toolBar2.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10),
84+
toolBar2.getBorder()));
85+
toolBar2.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
86+
toolBar2.add(new ToolBarButton(toolBar2));
87+
88+
JPanel topPanel = new JPanel(new GridLayout(2, 0));
89+
topPanel.add(toolBar);
90+
topPanel.add(toolBar2);
91+
frame.add(topPanel, BorderLayout.NORTH);
92+
93+
JToolBar toolBar3 = new JToolBar();
94+
toolBar3.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10),
95+
toolBar3.getBorder()));
96+
toolBar3.setOrientation(JToolBar.VERTICAL);
97+
toolBar3.add(new ToolBarButton(toolBar3));
98+
frame.add(toolBar3, BorderLayout.EAST);
99+
100+
frame.setSize(200, 200);
101+
return frame;
102+
}
103+
104+
static class ToolBarButton extends JButton {
105+
final JToolBar toolBar;
106+
107+
public ToolBarButton(JToolBar p_toolBar) {
108+
super("Change toolbar's orientation");
109+
this.toolBar = p_toolBar;
110+
addActionListener(e -> toolBar.setOrientation(1 - toolBar.getOrientation()));
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)