Skip to content
Open
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
26 changes: 21 additions & 5 deletions src/java.desktop/macosx/classes/com/apple/laf/AquaMenuPainter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -520,8 +520,11 @@ private String layoutMenuItem(final JMenuItem menuItem, final FontMetrics fm, fi
checkIconR.y = Math.abs(viewR.y + (labelR.height / 2) - (checkIconR.height / 2));
checkIconR.x = 5;

textR.width += 8;

if (AquaUtils.isLeftToRight(menuItem)) {
textR.width += 8;
} else {
arrowIconR.x -= 8;
}
}

/*System.out.println("Layout: " +horizontalAlignment+ " v=" +viewR+" c="+checkIconR+" i="+
Expand All @@ -531,13 +534,26 @@ private String layoutMenuItem(final JMenuItem menuItem, final FontMetrics fm, fi
// Flip the rectangles so that instead of [check][icon][text][accel/arrow] it's [accel/arrow][text][icon][check]
final int w = viewR.width;
checkIconR.x = w - (checkIconR.x + checkIconR.width);
if (menuItem.getHorizontalTextPosition() != SwingConstants.CENTER) {
int d = textR.x - iconR.x;
Copy link
Contributor

Choose a reason for hiding this comment

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

d refers to difference ? Could be diff for readability ?

if (d > 0) {
textR.x = iconR.x;
iconR.x = iconR.x + d + textR.width - iconR.width;
} else {
iconR.x = textR.x;
textR.x = iconR.x - d + iconR.width - textR.width;
}
}
iconR.x = w - (iconR.x + iconR.width);
textR.x = w - (textR.x + textR.width);
acceleratorR.x = w - (acceleratorR.x + acceleratorR.width);
arrowIconR.x = w - (arrowIconR.x + arrowIconR.width);
textR.x -= menuItemGap;
iconR.x -= menuItemGap;
} else {
textR.x += menuItemGap;
iconR.x += menuItemGap;
}
textR.x += menuItemGap;
iconR.x += menuItemGap;

return text;
}
Expand Down
12 changes: 12 additions & 0 deletions test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
* @run main/manual RightLeftOrientation windows
*/

/*
* @test id=aqua
* @bug 8371508
* @requires (os.family == "mac")
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess now the test can be run in window and mac OS ? Any idea on Nimbus L&F in windows os ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is Aqua LnF specific fix and Aqua LnF is only available on macOS so this exact test case can only be ran on mac. Initially test was used to validate the layout for Windows and Motif LnF. I haven't tried Nimbus yet. If there are problems with Nimbus on Windows they might be addressed separately.

* @summary Verifies that menu items lay out correctly
* in Aqua look and feel
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @run main/manual RightLeftOrientation aqua
*/

import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
Expand Down Expand Up @@ -96,6 +107,7 @@ public static void main(String[] args) throws Exception {
case "metal" -> lafClassName = UIManager.getCrossPlatformLookAndFeelClassName();
case "motif" -> lafClassName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
case "windows" -> lafClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
case "aqua" -> lafClassName = "com.apple.laf.AquaLookAndFeel";
default -> throw new IllegalArgumentException(
"Unsupported Look-and-Feel keyword for this test: " + args[0]);
}
Expand Down