Skip to content

Commit 5205eae

Browse files
committed
8346753: Test javax/swing/JMenuItem/RightLeftOrientation/RightLeftOrientation.java fails on Windows Server 2025 x64 because the icons of RBMenuItem and CBMenuItem are not visible in Nimbus LookAndFeel
Reviewed-by: abhiscxk
1 parent bbc5c98 commit 5205eae

File tree

1 file changed

+59
-36
lines changed

1 file changed

+59
-36
lines changed

test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,36 @@
2222
*/
2323

2424
/*
25-
* @test
25+
* @test id=metal
2626
* @bug 4211052
2727
* @requires (os.family == "windows")
28-
* @summary
29-
* This test checks if menu items lay out correctly when their
28+
* @summary Verifies if menu items lay out correctly when their
3029
* ComponentOrientation property is set to RIGHT_TO_LEFT.
31-
* The tester is asked to compare left-to-right and
32-
* right-to-left menus and judge whether they are mirror images of each
33-
* other.
3430
* @library /java/awt/regtesthelpers
3531
* @build PassFailJFrame
36-
* @run main/manual RightLeftOrientation
32+
* @run main/manual RightLeftOrientation metal
33+
*/
34+
35+
/*
36+
* @test id=motif
37+
* @bug 4211052
38+
* @requires (os.family == "windows")
39+
* @summary Verifies if menu items lay out correctly when their
40+
* ComponentOrientation property is set to RIGHT_TO_LEFT.
41+
* @library /java/awt/regtesthelpers
42+
* @build PassFailJFrame
43+
* @run main/manual RightLeftOrientation motif
44+
*/
45+
46+
/*
47+
* @test id=windows
48+
* @bug 4211052
49+
* @requires (os.family == "windows")
50+
* @summary Verifies if menu items lay out correctly when their
51+
* ComponentOrientation property is set to RIGHT_TO_LEFT.
52+
* @library /java/awt/regtesthelpers
53+
* @build PassFailJFrame
54+
* @run main/manual RightLeftOrientation windows
3755
*/
3856

3957
import java.awt.Color;
@@ -52,29 +70,47 @@
5270
import javax.swing.JMenuItem;
5371
import javax.swing.JRadioButtonMenuItem;
5472
import javax.swing.KeyStroke;
55-
import javax.swing.LookAndFeel;
5673
import javax.swing.SwingConstants;
74+
import javax.swing.SwingUtilities;
5775
import javax.swing.UIManager;
5876

5977
public class RightLeftOrientation {
6078

6179
private static final String INSTRUCTIONS = """
62-
A menu bar is shown containing a menu for each look and feel.
63-
A disabled menu means that the look and feel is not available for
64-
testing in this environment.
65-
Every effort should be made to run this test
66-
in an environment that covers all look and feels.
80+
A menu bar is shown with a menu.
6781
68-
Each menu is divided into two halves. The upper half is oriented
82+
The menu is divided into two halves. The upper half is oriented
6983
left-to-right and the lower half is oriented right-to-left.
70-
For each menu, ensure that the lower half mirrors the upper half.
84+
Ensure that the lower half mirrors the upper half.
7185
7286
Note that when checking the positioning of the sub-menus, it
7387
helps to position the frame away from the screen edges.""";
7488

7589
public static void main(String[] args) throws Exception {
90+
if (args.length < 1) {
91+
throw new IllegalArgumentException("Look-and-Feel keyword is required");
92+
}
93+
94+
final String lafClassName;
95+
switch (args[0]) {
96+
case "metal" -> lafClassName = UIManager.getCrossPlatformLookAndFeelClassName();
97+
case "motif" -> lafClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
98+
case "windows" -> lafClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
99+
default -> throw new IllegalArgumentException(
100+
"Unsupported Look-and-Feel keyword for this test: " + args[0]);
101+
}
102+
103+
SwingUtilities.invokeAndWait(() -> {
104+
try {
105+
UIManager.setLookAndFeel(lafClassName);
106+
} catch (Exception e) {
107+
throw new RuntimeException(e);
108+
}
109+
});
110+
111+
System.out.println("Test for LookAndFeel " + lafClassName);
112+
76113
PassFailJFrame.builder()
77-
.title("RightLeftOrientation Instructions")
78114
.instructions(INSTRUCTIONS)
79115
.columns(35)
80116
.testUI(RightLeftOrientation::createTestUI)
@@ -86,32 +122,19 @@ private static JFrame createTestUI() {
86122
JFrame frame = new JFrame("RightLeftOrientation");
87123
JMenuBar menuBar = new JMenuBar();
88124

89-
menuBar.add(createMenu("javax.swing.plaf.metal.MetalLookAndFeel",
90-
"Metal"));
91-
menuBar.add(createMenu("com.sun.java.swing.plaf.motif.MotifLookAndFeel",
92-
"Motif"));
93-
menuBar.add(createMenu("com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
94-
"Windows"));
125+
menuBar.add(createMenu());
95126

96127
frame.setJMenuBar(menuBar);
97-
frame.pack();
128+
frame.setSize(250, 70);
98129
return frame;
99130
}
100131

101132

102-
static JMenu createMenu(String laf, String name) {
103-
JMenu menu = new JMenu(name);
104-
try {
105-
LookAndFeel save = UIManager.getLookAndFeel();
106-
UIManager.setLookAndFeel(laf);
107-
addMenuItems(menu, ComponentOrientation.LEFT_TO_RIGHT);
108-
menu.addSeparator();
109-
addMenuItems(menu, ComponentOrientation.RIGHT_TO_LEFT);
110-
UIManager.setLookAndFeel(save);
111-
} catch (Exception e) {
112-
menu = new JMenu(name);
113-
menu.setEnabled(false);
114-
}
133+
static JMenu createMenu() {
134+
JMenu menu = new JMenu(UIManager.getLookAndFeel().getID());
135+
addMenuItems(menu, ComponentOrientation.LEFT_TO_RIGHT);
136+
menu.addSeparator();
137+
addMenuItems(menu, ComponentOrientation.RIGHT_TO_LEFT);
115138
return menu;
116139
}
117140

0 commit comments

Comments
 (0)