Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8784a0

Browse files
committed
8370465: Right to Left Orientation Issues with MenuItem Component
Backport-of: aeb92e8d9059ca37000a6d92fbf5079a919f812c
1 parent78564fd commita8784a0

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
privatestaticWindowsMenuItemUIAccessorgetAccessor(

‎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
importjavax.swing.JComponent;
4444
importjavax.swing.JMenu;
4545
importjavax.swing.JMenuItem;
46+
importjavax.swing.SwingConstants;
4647
importjavax.swing.UIManager;
4748
importjavax.swing.plaf.ComponentUI;
4849
importjavax.swing.plaf.UIResource;
@@ -215,8 +216,17 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g,
215216

216217
if (lh.getCheckIcon() !=null &&lh.useCheckAndArrow()) {
217218
Rectanglerect =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
Rectanglerect =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 =newJMenuItem("Text to the left",newMyMenuItemIcon());
159+
menuItem.setComponentOrientation(o);
160+
menuItem.setHorizontalTextPosition(SwingConstants.LEFT);
161+
menu.add(menuItem);
162+
163+
menuItem =newJMenuItem("Text to the right",newMyMenuItemIcon());
164+
menuItem.setComponentOrientation(o);
165+
menuItem.setHorizontalTextPosition(SwingConstants.RIGHT);
166+
menu.add(menuItem);
167+
158168
menuItem =newJRadioButtonMenuItem("Radio Button Menu Item");
159169
menuItem.setComponentOrientation(o);
160170
menuItem.setSelected(true);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp