Skip to content

Commit cba09cd

Browse files
committed
5107379: Component orientation in JOptionPane is not proper in Motif L&F.
Reviewed-by: tr, kizune
1 parent 020e3f9 commit cba09cd

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

src/java.desktop/share/classes/com/sun/java/swing/plaf/motif/MotifOptionPaneUI.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 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
@@ -25,6 +25,7 @@
2525

2626
package com.sun.java.swing.plaf.motif;
2727

28+
import java.awt.BorderLayout;
2829
import java.awt.Color;
2930
import java.awt.Container;
3031
import java.awt.Dimension;
@@ -102,7 +103,7 @@ protected void addIcon(Container top) {
102103
JLabel iconLabel = new JLabel(sideIcon);
103104

104105
iconLabel.setVerticalAlignment(SwingConstants.CENTER);
105-
top.add(iconLabel, "West");
106+
top.add(iconLabel, BorderLayout.BEFORE_LINE_BEGINS);
106107
}
107108
}
108109

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 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 5107379
27+
* @summary Component orientation in JOptionPane is not proper in Motif L&F.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual TestIconRTL
31+
*/
32+
33+
import java.awt.ComponentOrientation;
34+
import java.util.concurrent.atomic.AtomicBoolean;
35+
import javax.swing.JFrame;
36+
import javax.swing.JMenu;
37+
import javax.swing.JMenuBar;
38+
import javax.swing.JMenuItem;
39+
import javax.swing.JOptionPane;
40+
import javax.swing.SwingUtilities;
41+
import javax.swing.UIManager;
42+
43+
public class TestIconRTL {
44+
45+
private static JFrame frame;
46+
private static JOptionPane pane;
47+
48+
static final String INSTRUCTIONS = """
49+
A JOptionPane is shown in Motif LookAndFeel with "Orientation" menu.
50+
Click on "Orientation" menu and
51+
test with "Left To Right" and "Right to Left" Orientation
52+
If JOptionPane is drawn properly in different orientation,
53+
then test passed, otherwise it failed.""";
54+
55+
public static void main(String[] args) throws Exception {
56+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
57+
PassFailJFrame.builder()
58+
.title("TestIconRTL Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.columns(60)
61+
.testUI(TestIconRTL::createTestUI)
62+
.build()
63+
.awaitAndCheck();
64+
}
65+
66+
static JFrame createTestUI() {
67+
pane = new JOptionPane(new String("Testing CCC4265463"),
68+
JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
69+
pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
70+
pane.setVisible(true);
71+
72+
frame = new JFrame("TestIconRTL");
73+
74+
JMenuBar menuBar = new JMenuBar();
75+
menuBar.add(getOrientationJMenu());
76+
77+
frame.setJMenuBar(menuBar);
78+
79+
frame.getContentPane().add(pane);
80+
frame.pack();
81+
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
82+
frame.setLocationRelativeTo(null);
83+
return frame;
84+
}
85+
86+
public static void test() throws Exception {
87+
AtomicBoolean leftToRightOrientationFlag = new AtomicBoolean(false);
88+
SwingUtilities.invokeAndWait(() -> leftToRightOrientationFlag.set(pane.getComponentOrientation().isLeftToRight()));
89+
if (leftToRightOrientationFlag.get()) {
90+
System.out.println("LTR LOCATION ...");
91+
} else {
92+
System.out.println("RTL LOCATION ...");
93+
}
94+
}
95+
96+
private static JMenu getOrientationJMenu() {
97+
JMenu lafMenu = new JMenu("Orientation");
98+
JMenuItem leftToRight = new JMenuItem("Left to Right");
99+
leftToRight.addActionListener(e -> {
100+
pane.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
101+
pane.invalidate();
102+
SwingUtilities.updateComponentTreeUI(frame);
103+
});
104+
105+
JMenuItem rightToLeft = new JMenuItem("Right to Left");
106+
rightToLeft.addActionListener(e -> {
107+
pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
108+
pane.invalidate();
109+
SwingUtilities.updateComponentTreeUI(frame);
110+
});
111+
112+
pane.invalidate();
113+
lafMenu.add(leftToRight);
114+
lafMenu.add(rightToLeft);
115+
return lafMenu;
116+
}
117+
118+
119+
}

0 commit comments

Comments
 (0)