Skip to content

Commit ab821aa

Browse files
author
Tejesh R
committed
6442919: JFilechooser popup still left-to-right when JFilechooser is set to right-to-left
Reviewed-by: serb, abhiscxk
1 parent 0328886 commit ab821aa

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/java.desktop/share/classes/sun/swing/FilePane.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, 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
@@ -1932,6 +1932,8 @@ public JPopupMenu getComponentPopupMenu() {
19321932
if (viewMenu != null) {
19331933
viewMenu.getPopupMenu().setInvoker(viewMenu);
19341934
}
1935+
1936+
contextMenu.applyComponentOrientation(getFileChooser().getComponentOrientation());
19351937
return contextMenu;
19361938
}
19371939

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2023, 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+
import java.awt.ComponentOrientation;
25+
26+
import javax.swing.JComponent;
27+
import javax.swing.JFileChooser;
28+
import javax.swing.JPopupMenu;
29+
import javax.swing.SwingUtilities;
30+
import javax.swing.UIManager;
31+
import javax.swing.UnsupportedLookAndFeelException;
32+
33+
/*
34+
* @test
35+
* @bug 6442919
36+
* @library ../regtesthelpers
37+
* @build Util
38+
* @summary Test to check the orientation of Popup menu is set
39+
* as per FileChooser orientation.
40+
* @run main FCPopupMenuOrientationTest
41+
*/
42+
43+
public class FCPopupMenuOrientationTest {
44+
public static void main(String[] args) throws Exception {
45+
SwingUtilities.invokeAndWait(new Runnable() {
46+
@Override
47+
public void run() {
48+
for (UIManager.LookAndFeelInfo laf :
49+
UIManager.getInstalledLookAndFeels()) {
50+
String className = laf.getName().toLowerCase();
51+
if (className.contains("motif")
52+
|| className.contains("mac")
53+
|| className.contains("gtk")) {
54+
continue;
55+
}
56+
setLookAndFeel(laf);
57+
JFileChooser fc = new JFileChooser();
58+
fc.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
59+
60+
JComponent comp = (JComponent) Util.findSubComponent(
61+
fc, "FilePane");
62+
JPopupMenu popupMenu = comp.getComponentPopupMenu();
63+
if (popupMenu.getComponentOrientation() !=
64+
fc.getComponentOrientation()) {
65+
throw new RuntimeException("File Chooser component " +
66+
"orientation doesn't match with PopupMenu");
67+
}
68+
}
69+
}
70+
});
71+
System.out.println("Test Pass");
72+
}
73+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
74+
try {
75+
UIManager.setLookAndFeel(laf.getClassName());
76+
System.out.println("Set L&F : " + laf.getName());
77+
} catch (UnsupportedLookAndFeelException ignored) {
78+
System.out.println("Unsupported LookAndFeel: " + laf.getClassName());
79+
} catch (ClassNotFoundException | InstantiationException |
80+
IllegalAccessException e) {
81+
throw new RuntimeException(e);
82+
}
83+
}
84+
}
85+

0 commit comments

Comments
 (0)