Skip to content

Commit bf63f9f

Browse files
author
Harshitha Onkar
committed
8353319: Open source Swing tests - Set 3
Reviewed-by: abhiscxk, dnguyen
1 parent abbf1a0 commit bf63f9f

File tree

4 files changed

+349
-21
lines changed

4 files changed

+349
-21
lines changed
Lines changed: 107 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2025, 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
@@ -28,55 +28,141 @@
2828
* @library /java/awt/regtesthelpers
2929
* @build PassFailJFrame
3030
* @run main/manual bug4419914
31-
*/
31+
*/
3232

3333
import java.awt.BorderLayout;
3434
import java.awt.ComponentOrientation;
35+
import java.awt.Frame;
36+
import java.awt.Window;
37+
import java.util.List;
38+
import java.util.Locale;
3539
import javax.swing.JButton;
40+
import javax.swing.JDialog;
3641
import javax.swing.JFrame;
37-
import java.util.Locale;
42+
import javax.swing.JLabel;
43+
import javax.swing.JWindow;
3844

3945
public class bug4419914 {
46+
private static JFrame frame;
4047
private static final String INSTRUCTIONS = """
41-
1. You will see a frame with five buttons.
42-
2. Confirm that each button is placed as follows:
43-
NORTH
44-
END CENTER START
45-
SOUTH
46-
3. Press the "NORTH" button and confirm the button is focused.
47-
4. Press TAB repeatedly and confirm that the TAB focus moves from right to left.
48-
(NORTH - START - CENTER - END - SOUTH - NORTH - START - CENTER - ...)
48+
This test verifies tab movement on RTL component orientation
49+
in JWindow, JFrame and JDialog.
50+
51+
When test starts 3 test windows are displayed - JFrame, JWindow and JDialog.
52+
Follow the instructions below and if any condition does not hold
53+
press FAIL.
54+
55+
1. Confirm that each button in the child window is placed as follows:
56+
57+
For JFrame:
58+
NORTH
59+
END CENTER START
60+
SOUTH
61+
62+
For JWindow:
63+
END CENTER START
64+
QUIT
65+
66+
For JDialog:
67+
END CENTER START
68+
69+
3. Press on the "START" button in case of JWindow & JDialog and "NORTH"
70+
in case of JFrame, confirm that the respective button is focused.
71+
72+
4. Press TAB repeatedly and confirm that the TAB focus moves
73+
from right to left.
74+
75+
For JFrame:
76+
(NORTH - START - CENTER - END - SOUTH - NORTH - START - CENTER - ...)
4977
50-
If there's anything different from the above items, click Fail else click Pass.""";
78+
For JWindow:
79+
(START - CENTER - END - QUIT - START - CENTER - END - QUIT - ...)
80+
81+
For JDialog:
82+
(START - CENTER - END - START - CENTER - END - ...)
83+
84+
If all of the above conditions are true press PASS else FAIL.
85+
""";
5186

5287
public static void main(String[] args) throws Exception {
5388
PassFailJFrame.builder()
54-
.title("Tab movement Instructions")
5589
.instructions(INSTRUCTIONS)
56-
.rows((int) INSTRUCTIONS.lines().count() + 2)
57-
.columns(48)
58-
.testUI(bug4419914::createTestUI)
90+
.columns(45)
91+
.testTimeOut(10)
92+
.testUI(bug4419914::createAndShowUI)
93+
.positionTestUI(WindowLayouts::rightOneColumn)
5994
.build()
6095
.awaitAndCheck();
6196
}
6297

63-
private static JFrame createTestUI() {
64-
JFrame frame = new JFrame("bug4419914");
98+
private static List<Window> createAndShowUI() {
99+
return List.of(createJFrame(), createJWindow(), createJDialog());
100+
}
101+
102+
private static JFrame createJFrame() {
103+
frame = new JFrame("bug4419914 JFrame");
65104
frame.setFocusCycleRoot(true);
105+
// Tab movement set to RTL
66106
frame.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
67107
frame.setLocale(Locale.ENGLISH);
68108
frame.enableInputMethods(false);
69109

110+
// Component placement within content pane set to RTL
70111
frame.getContentPane().setComponentOrientation(
71-
ComponentOrientation.RIGHT_TO_LEFT);
112+
ComponentOrientation.RIGHT_TO_LEFT);
72113
frame.getContentPane().setLocale(Locale.ENGLISH);
73-
frame.getContentPane().setLayout(new BorderLayout());
114+
frame.setLayout(new BorderLayout());
74115
frame.add(new JButton("SOUTH"), BorderLayout.SOUTH);
75116
frame.add(new JButton("CENTER"), BorderLayout.CENTER);
76117
frame.add(new JButton("END"), BorderLayout.LINE_END);
77118
frame.add(new JButton("START"), BorderLayout.LINE_START);
78119
frame.add(new JButton("NORTH"), BorderLayout.NORTH);
79-
frame.setSize(300, 150);
120+
frame.setSize(300, 160);
80121
return frame;
81122
}
123+
124+
private static JWindow createJWindow() {
125+
JWindow window = new JWindow(frame);
126+
window.setFocusableWindowState(true);
127+
// Tab movement set to RTL
128+
window.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
129+
window.setLocale(new Locale("en"));
130+
window.enableInputMethods(false);
131+
132+
// Component placement within content pane set to RTL
133+
window.getContentPane().setComponentOrientation(
134+
ComponentOrientation.RIGHT_TO_LEFT);
135+
window.getContentPane().setLocale(new Locale("en"));
136+
window.setLayout(new BorderLayout());
137+
window.add(new JLabel("bug4419914 JWindow"), BorderLayout.NORTH);
138+
window.add(new JButton("START"), BorderLayout.LINE_START);
139+
window.add(new JButton("CENTER"), BorderLayout.CENTER);
140+
window.add(new JButton("END"), BorderLayout.LINE_END);
141+
142+
JButton quitButton = new JButton("QUIT");
143+
quitButton.addActionListener(e1 -> window.dispose());
144+
window.add(quitButton, BorderLayout.SOUTH);
145+
window.setSize(300, 153);
146+
window.requestFocus();
147+
return window;
148+
}
149+
150+
private static JDialog createJDialog() {
151+
JDialog dialog = new JDialog((Frame) null, "bug4419914 JDialog");
152+
// Tab movement set to RTL
153+
dialog.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
154+
dialog.setLocale(new Locale("en"));
155+
dialog.enableInputMethods(false);
156+
157+
// Component placement within content pane set to RTL
158+
dialog.getContentPane().setComponentOrientation(
159+
ComponentOrientation.RIGHT_TO_LEFT);
160+
dialog.getContentPane().setLocale(new Locale("en"));
161+
dialog.setLayout(new BorderLayout());
162+
dialog.add(new JButton("CENTER"), BorderLayout.CENTER);
163+
dialog.add(new JButton("END"), BorderLayout.LINE_END);
164+
dialog.add(new JButton("START"), BorderLayout.LINE_START);
165+
dialog.setSize(300, 160);
166+
return dialog;
167+
}
82168
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) 2002, 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 4614623
27+
* @requires (os.family == "windows")
28+
* @summary Tests that w2k mnemonic underlining works when there's no
29+
focus owner
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual bug4614623
33+
*/
34+
35+
import javax.swing.JFrame;
36+
import javax.swing.JMenu;
37+
import javax.swing.JMenuBar;
38+
import javax.swing.UIManager;
39+
40+
public class bug4614623 {
41+
private static final String INSTRUCTIONS = """
42+
This test verifies if the short-cut character
43+
(menu mnemonic) is underlined when the ALT key is held down.
44+
45+
Check if the following is true.
46+
1) Press Alt key. The letter 'F' (menu mnemonic) of
47+
the "File" menu should now be underlined.
48+
2) Release the Alt key, the selection background (light grey)
49+
should appear around the "File" menu. Compare "About" menu
50+
with "File" menu to see the light grey selection background.
51+
52+
If the above is true, press PASS else FAIL.
53+
""";
54+
55+
public static void main(String[] args) throws Exception {
56+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
57+
58+
PassFailJFrame.builder()
59+
.instructions(INSTRUCTIONS)
60+
.columns(62)
61+
.rows(12)
62+
.testUI(bug4614623::createAndShowUI)
63+
.build()
64+
.awaitAndCheck();
65+
}
66+
67+
public static JFrame createAndShowUI() {
68+
JFrame frame = new JFrame("bug4614623 - File menu test");
69+
JMenuBar menuBar = new JMenuBar();
70+
71+
JMenu fileMenu = new JMenu("File");
72+
fileMenu.setMnemonic('F');
73+
menuBar.add(fileMenu);
74+
75+
JMenu about = new JMenu("About");
76+
menuBar.add(about);
77+
menuBar.setSize(300, 100);
78+
79+
frame.setJMenuBar(menuBar);
80+
menuBar.requestFocus();
81+
frame.setSize(300, 200);
82+
return frame;
83+
}
84+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 4613811
27+
* @summary Scrollable Buttons of JTabbedPane don't
28+
* get enabled or disabled on selecting tab
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4613811
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import javax.swing.JFrame;
36+
import javax.swing.JLabel;
37+
import javax.swing.JTabbedPane;
38+
39+
public class bug4613811 {
40+
private static final String INSTRUCTIONS = """
41+
Select different tabs and check that the scrollable
42+
buttons are correctly enabled and disabled.
43+
44+
When the very first tab (Tab 1) is fully visible
45+
On macOS:
46+
the left arrow button should NOT be visible.
47+
48+
On other platforms:
49+
the left arrow button should be disabled.
50+
51+
If the last tab (Tab 5) is fully visible
52+
On macOS:
53+
the right arrow button should NOT be visible.
54+
55+
On other platforms:
56+
the right arrow button should be disabled.
57+
58+
If the above is true press PASS else FAIL.
59+
""";
60+
61+
public static void main(String[] args) throws Exception {
62+
PassFailJFrame.builder()
63+
.instructions(INSTRUCTIONS)
64+
.columns(30)
65+
.testUI(bug4613811::createAndShowUI)
66+
.build()
67+
.awaitAndCheck();
68+
}
69+
70+
private static JFrame createAndShowUI() {
71+
JFrame frame = new JFrame("bug4613811 - JTabbedPane Test");
72+
final JTabbedPane tabPane = new JTabbedPane(JTabbedPane.TOP,
73+
JTabbedPane.SCROLL_TAB_LAYOUT);
74+
for (int i = 1; i <= 5; i++) {
75+
tabPane.addTab("TabbedPane: Tab " + i, null, new JLabel("Tab " + i));
76+
}
77+
frame.add(tabPane, BorderLayout.CENTER);
78+
frame.setResizable(false);
79+
frame.setSize(400, 200);
80+
return frame;
81+
}
82+
}

0 commit comments

Comments
 (0)