Skip to content

Commit fc5df4a

Browse files
committed
8370465: Right to Left Orientation Issues with MenuItem Component
Reviewed-by: kizune, honkar
1 parent 4f9f086 commit fc5df4a

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,15 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
914914
}
915915
}
916916
if (icon != null) {
917-
icon.paintIcon(c, g, x + VistaMenuItemCheckIconFactory.getIconWidth(),
918-
y + OFFSET);
917+
if (WindowsGraphicsUtils.isLeftToRight(c)) {
918+
icon.paintIcon(c, g,
919+
x + VistaMenuItemCheckIconFactory.getIconWidth(),
920+
y + OFFSET);
921+
} else {
922+
icon.paintIcon(c, g,
923+
x - VistaMenuItemCheckIconFactory.getIconWidth() + 2 * OFFSET,
924+
y + OFFSET);
925+
}
919926
}
920927
}
921928
private static WindowsMenuItemUIAccessor getAccessor(

src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import javax.swing.JComponent;
3939
import javax.swing.JMenu;
4040
import javax.swing.JMenuItem;
41+
import javax.swing.SwingConstants;
4142
import javax.swing.UIManager;
4243
import javax.swing.plaf.ComponentUI;
4344
import javax.swing.plaf.UIResource;
@@ -201,8 +202,17 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
201202

202203
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
203204
Rectangle rect = lr.getTextRect();
204-
205-
rect.x += lh.getAfterCheckIconGap();
205+
if (menuItem.getComponentOrientation().isLeftToRight()) {
206+
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
207+
&& menuItem.getHorizontalTextPosition() != SwingConstants.LEFT) {
208+
rect.x += lh.getAfterCheckIconGap();
209+
}
210+
} else {
211+
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
212+
&& menuItem.getHorizontalTextPosition() != SwingConstants.RIGHT) {
213+
rect.x -= lh.getAfterCheckIconGap();
214+
}
215+
}
206216

207217
lr.setTextRect(rect);
208218
}
@@ -218,7 +228,11 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
218228
}
219229
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
220230
Rectangle rect = lr.getAccRect();
221-
rect.x += lh.getAfterCheckIconGap();
231+
if (menuItem.getComponentOrientation().isLeftToRight()) {
232+
rect.x += lh.getAfterCheckIconGap();
233+
} else {
234+
rect.x -= lh.getAfterCheckIconGap();
235+
}
222236
lr.setAccRect(rect);
223237
}
224238
SwingUtilities3.paintAccText(g, lh, lr, disabledForeground,

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
/*
4747
* @test id=windows
48-
* @bug 4211052
48+
* @bug 4211052 8370465
4949
* @requires (os.family == "windows")
5050
* @summary Verifies if menu items lay out correctly when their
5151
* ComponentOrientation property is set to RIGHT_TO_LEFT.
@@ -155,6 +155,16 @@ static void addMenuItems(JMenu menu, ComponentOrientation o) {
155155
menuItem.setHorizontalTextPosition(SwingConstants.LEADING);
156156
menu.add(menuItem);
157157

158+
menuItem = new JMenuItem("Text to the left", new MyMenuItemIcon());
159+
menuItem.setComponentOrientation(o);
160+
menuItem.setHorizontalTextPosition(SwingConstants.LEFT);
161+
menu.add(menuItem);
162+
163+
menuItem = new JMenuItem("Text to the right", new MyMenuItemIcon());
164+
menuItem.setComponentOrientation(o);
165+
menuItem.setHorizontalTextPosition(SwingConstants.RIGHT);
166+
menu.add(menuItem);
167+
158168
menuItem = new JRadioButtonMenuItem("Radio Button Menu Item");
159169
menuItem.setComponentOrientation(o);
160170
menuItem.setSelected(true);

0 commit comments

Comments
 (0)