Skip to content

Commit b78ff0d

Browse files
author
duke
committed
Backport fc5df4ac8f11f25611bd4def5b655578af27c882
1 parent c578eb2 commit b78ff0d

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
@@ -882,8 +882,15 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
882882
}
883883
}
884884
if (icon != null) {
885-
icon.paintIcon(c, g, x + VistaMenuItemCheckIconFactory.getIconWidth(),
886-
y + OFFSET);
885+
if (WindowsGraphicsUtils.isLeftToRight(c)) {
886+
icon.paintIcon(c, g,
887+
x + VistaMenuItemCheckIconFactory.getIconWidth(),
888+
y + OFFSET);
889+
} else {
890+
icon.paintIcon(c, g,
891+
x - VistaMenuItemCheckIconFactory.getIconWidth() + 2 * OFFSET,
892+
y + OFFSET);
893+
}
887894
}
888895
}
889896
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
@@ -43,6 +43,7 @@
4343
import javax.swing.JComponent;
4444
import javax.swing.JMenu;
4545
import javax.swing.JMenuItem;
46+
import javax.swing.SwingConstants;
4647
import javax.swing.UIManager;
4748
import javax.swing.plaf.ComponentUI;
4849
import javax.swing.plaf.UIResource;
@@ -215,8 +216,17 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
215216

216217
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
217218
Rectangle rect = lr.getTextRect();
218-
219-
rect.x += lh.getAfterCheckIconGap();
219+
if (menuItem.getComponentOrientation().isLeftToRight()) {
220+
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
221+
&& menuItem.getHorizontalTextPosition() != SwingConstants.LEFT) {
222+
rect.x += lh.getAfterCheckIconGap();
223+
}
224+
} else {
225+
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
226+
&& menuItem.getHorizontalTextPosition() != SwingConstants.RIGHT) {
227+
rect.x -= lh.getAfterCheckIconGap();
228+
}
229+
}
220230

221231
lr.setTextRect(rect);
222232
}
@@ -232,7 +242,11 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
232242
}
233243
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
234244
Rectangle rect = lr.getAccRect();
235-
rect.x += lh.getAfterCheckIconGap();
245+
if (menuItem.getComponentOrientation().isLeftToRight()) {
246+
rect.x += lh.getAfterCheckIconGap();
247+
} else {
248+
rect.x -= lh.getAfterCheckIconGap();
249+
}
236250
lr.setAccRect(rect);
237251
}
238252
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)