From 9ae94ead40df97b57f50fc0feaf0ae1706495327 Mon Sep 17 00:00:00 2001 From: Alexander Zuev Date: Sat, 8 Nov 2025 15:12:57 -0800 Subject: [PATCH 1/2] 8371508: [macos] In Aqua LaF menu items layout is incorrect in RTL orientation Fixed the components orientation; Added Aqua test to the existing manual case; --- .../com/apple/laf/AquaMenuPainter.java | 26 +++++++++++++++---- .../swing/JMenuItem/RightLeftOrientation.java | 12 +++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuPainter.java b/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuPainter.java index b7878b67483c2..0731cb0b50cf4 100644 --- a/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuPainter.java +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaMenuPainter.java @@ -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 @@ -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="+ @@ -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; + 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; } diff --git a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java index 247d8b52541b8..c6d5c63c766d3 100644 --- a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java +++ b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java @@ -54,6 +54,17 @@ * @run main/manual RightLeftOrientation windows */ +/* + * @test id=aqua + * @bug 8022522 + * @requires (os.family == "mac") + * @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; @@ -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]); } From 0427d6a18ab1d1f945154e1f513d67cea34f491e Mon Sep 17 00:00:00 2001 From: Alexander Zuev Date: Sat, 8 Nov 2025 15:22:31 -0800 Subject: [PATCH 2/2] Use correct bug id in the test. --- test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java index c6d5c63c766d3..f2bc3e3f573ce 100644 --- a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java +++ b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java @@ -56,7 +56,7 @@ /* * @test id=aqua - * @bug 8022522 + * @bug 8371508 * @requires (os.family == "mac") * @summary Verifies that menu items lay out correctly * in Aqua look and feel