11/*
2- * Copyright (c) 2007, 2024 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2007, 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
2020 * or visit www.oracle.com if you need additional information or have any
2121 * questions.
2222 */
23+
2324/*
2425 * @test
2526 * @bug 4211731 4214512
2627 * @summary
2728 * This test checks if menu bars lay out correctly when their
28- * ComponentOrientation property is set to RIGHT_TO_LEFT. This test is
29- * manual. The tester is asked to compare left-to-right and
30- * right-to-left menu bars and judge whether they are mirror images of each
31- * other.
29+ * ComponentOrientation property is set to RIGHT_TO_LEFT.
30+ * The tester is asked to compare left-to-right and
31+ * right-to-left menu bars and decide whether they are mirror
32+ * images of each other.
3233 * @library /test/jdk/java/awt/regtesthelpers
3334 * @build PassFailJFrame
3435 * @run main/manual RightLeftOrientation
3536 */
3637
3738import java .awt .ComponentOrientation ;
38- import java .awt .Point ;
3939import java .awt .event .ActionEvent ;
4040import java .awt .event .ActionListener ;
41+ import java .util .List ;
42+
4143import javax .swing .ButtonGroup ;
4244import javax .swing .JFrame ;
4345import javax .swing .JMenu ;
4446import javax .swing .JMenuBar ;
47+ import javax .swing .JOptionPane ;
4548import javax .swing .JPanel ;
4649import javax .swing .JRadioButton ;
4750import javax .swing .SwingUtilities ;
4851import javax .swing .UIManager ;
4952
50- public class RightLeftOrientation {
53+ public final class RightLeftOrientation {
5154
52- static JFrame ltrFrame ;
53- static JFrame rtlFrame ;
55+ private static List <JFrame > frames ;
5456
5557 private static final String INSTRUCTIONS = """
56- This test checks menu bars for correct Right-To-Left Component Orientation.
57-
58- You should see two frames, each containing a menu bar.
58+ This test checks menu bars for correct Right-To-Left component orientation.
5959
60- One frame will be labelled "Left To Right" and will contain
60+ You should see two frames, each contains a menu bar.
61+ One frame is labelled "Left To Right" and contains
6162 a menu bar with menus starting on its left side.
62- The other frame will be labelled "Right To Left" and will
63- contain a menu bar with menus starting on its right side.
63+ The other frame is labelled "Right To Left" and
64+ contains a menu bar with menus starting on its right side.
6465
65- The test will also contain radio buttons that can be used to set
66- the look and feel of the menu bars.
67- For each look and feel, you should compare the two menu
68- bars and make sure they are mirror images of each other. """ ;
66+ The test also displays a frame with radio buttons
67+ to change the look and feel of the menu bars.
68+ For each look and feel, compare the two menu bars
69+ in LTR and RTL orientation and make sure they are mirror
70+ images of each other.""" ;
6971
7072 public static void main (String [] args ) throws Exception {
7173 PassFailJFrame .builder ()
72- .title ("RTL test Instructions" )
74+ .title ("Menu Bar RTL Instructions" )
7375 .instructions (INSTRUCTIONS )
74- .rows ((int ) INSTRUCTIONS .lines ().count () + 2 )
7576 .columns (30 )
7677 .testUI (RightLeftOrientation ::createTestUI )
78+ .positionTestUIRightColumn ()
7779 .build ()
7880 .awaitAndCheck ();
7981 }
8082
81- private static JFrame createTestUI () {
82- JFrame frame = new JFrame ("RightLeftOrientation " );
83+ private static JFrame createPlafChangerFrame () {
84+ JFrame frame = new JFrame ("Change Look and Feel " );
8385 JPanel panel = new JPanel ();
8486
8587 ButtonGroup group = new ButtonGroup ();
86- JRadioButton rb ;
8788 ActionListener plafChanger = new PlafChanger ();
8889
8990 UIManager .LookAndFeelInfo [] lafInfos = UIManager .getInstalledLookAndFeels ();
9091 for (int i = 0 ; i < lafInfos .length ; i ++) {
91- rb = new JRadioButton (lafInfos [i ].getName ());
92+ JRadioButton rb = new JRadioButton (lafInfos [i ].getName ());
9293 rb .setActionCommand (lafInfos [i ].getClassName ());
9394 rb .addActionListener (plafChanger );
9495 group .add (rb );
@@ -99,33 +100,39 @@ private static JFrame createTestUI() {
99100 }
100101
101102 frame .add (panel );
103+ frame .pack ();
104+ return frame ;
105+ }
102106
103- ltrFrame = new JFrame ("Left To Right" );
107+ private static List <JFrame > createTestUI () {
108+ JFrame plafFrame = createPlafChangerFrame ();
109+
110+ JFrame ltrFrame = new JFrame ("Left To Right" );
104111 ltrFrame .setJMenuBar (createMenuBar (ComponentOrientation .LEFT_TO_RIGHT ));
105112 ltrFrame .setSize (400 , 100 );
106- ltrFrame .setLocation (new Point (10 , 10 ));
107- ltrFrame .setVisible (true );
108113
109- rtlFrame = new JFrame ("Right To Left" );
114+ JFrame rtlFrame = new JFrame ("Right To Left" );
110115 rtlFrame .setJMenuBar (createMenuBar (ComponentOrientation .RIGHT_TO_LEFT ));
111116 rtlFrame .setSize (400 , 100 );
112- rtlFrame .setLocation (new Point (10 , 120 ));
113- rtlFrame .setVisible (true );
114- frame .pack ();
115- return frame ;
117+
118+ return (frames = List .of (plafFrame , ltrFrame , rtlFrame ));
116119 }
117120
118- static class PlafChanger implements ActionListener {
121+ private static final class PlafChanger implements ActionListener {
122+ @ Override
119123 public void actionPerformed (ActionEvent e ) {
120124 String lnfName = e .getActionCommand ();
121125
122126 try {
123127 UIManager .setLookAndFeel (lnfName );
124- SwingUtilities .updateComponentTreeUI (ltrFrame );
125- SwingUtilities .updateComponentTreeUI (rtlFrame );
126- }
127- catch (Exception exc ) {
128- System .err .println ("Could not load LookAndFeel: " + lnfName );
128+ frames .forEach (SwingUtilities ::updateComponentTreeUI );
129+ } catch (Exception exc ) {
130+ String message = "Could not set Look and Feel to " + lnfName ;
131+ System .err .println (message );
132+ JOptionPane .showMessageDialog (frames .get (0 ),
133+ message ,
134+ "Look and Feel Error" ,
135+ JOptionPane .ERROR_MESSAGE );
129136 }
130137
131138 }
0 commit comments