Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,15 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
}
}
if (icon != null) {
icon.paintIcon(c, g, x + VistaMenuItemCheckIconFactory.getIconWidth(),
y + OFFSET);
if (WindowsGraphicsUtils.isLeftToRight(c)) {
icon.paintIcon(c, g,
x + VistaMenuItemCheckIconFactory.getIconWidth(),
y + OFFSET);
} else {
icon.paintIcon(c, g,
x - VistaMenuItemCheckIconFactory.getIconWidth() + 2 * OFFSET,
y + OFFSET);
}
}
}
private static WindowsMenuItemUIAccessor getAccessor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
Expand Down Expand Up @@ -201,8 +202,17 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,

if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
Rectangle rect = lr.getTextRect();

rect.x += lh.getAfterCheckIconGap();
if (menuItem.getComponentOrientation().isLeftToRight()) {
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
&& menuItem.getHorizontalTextPosition() != SwingConstants.LEFT) {
rect.x += lh.getAfterCheckIconGap();
}
} else {
if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING
&& menuItem.getHorizontalTextPosition() != SwingConstants.RIGHT) {
rect.x -= lh.getAfterCheckIconGap();
}
}

lr.setTextRect(rect);
}
Expand All @@ -218,7 +228,11 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
}
if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) {
Rectangle rect = lr.getAccRect();
rect.x += lh.getAfterCheckIconGap();
if (menuItem.getComponentOrientation().isLeftToRight()) {
rect.x += lh.getAfterCheckIconGap();
} else {
rect.x -= lh.getAfterCheckIconGap();
}
lr.setAccRect(rect);
}
SwingUtilities3.paintAccText(g, lh, lr, disabledForeground,
Expand Down
12 changes: 11 additions & 1 deletion test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

/*
* @test id=windows
* @bug 4211052
* @bug 4211052 8370465
Copy link
Contributor

@honkar-jdk honkar-jdk Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of multiple separate jtreg tags for each LaF we can combine it using @run tags as below:

/*
...
...
 * @run main/manual RightLeftOrientation windows
 * @run main/manual RightLeftOrientation motif
 * @run main/manual RightLeftOrientation metal
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to use it that way in [8346753](#25907 (comment)) sometime back

* @requires (os.family == "windows")
* @summary Verifies if menu items lay out correctly when their
* ComponentOrientation property is set to RIGHT_TO_LEFT.
Expand Down Expand Up @@ -155,6 +155,16 @@ static void addMenuItems(JMenu menu, ComponentOrientation o) {
menuItem.setHorizontalTextPosition(SwingConstants.LEADING);
menu.add(menuItem);

menuItem = new JMenuItem("Text to the left", new MyMenuItemIcon());
menuItem.setComponentOrientation(o);
menuItem.setHorizontalTextPosition(SwingConstants.LEFT);
menu.add(menuItem);

menuItem = new JMenuItem("Text to the right", new MyMenuItemIcon());
menuItem.setComponentOrientation(o);
menuItem.setHorizontalTextPosition(SwingConstants.RIGHT);
menu.add(menuItem);

menuItem = new JRadioButtonMenuItem("Radio Button Menu Item");
menuItem.setComponentOrientation(o);
menuItem.setSelected(true);
Expand Down