Skip to content

Conversation

@prsadhuk
Copy link
Contributor

@prsadhuk prsadhuk commented Dec 18, 2025

Check/radiobutton icon are not aligned properly in RTL. WindowsMenuItemUI uses MenuItemLayoutHelper.layoutMenuItem to do the layout which calls doRTLColumnLayout which calculates x positions in calcXPositionsRTL and then again aligns in alignRects. However, since in Windows historically radiobutton/check icon was not drawn or drawn below the menuitem image icon (since image icon and check icon was drawn in the same layout space and not separately) the aligned x position of check icons returned from MenuItemLayoutHelper was not correct but since MenuItemLayoutHelper alignment is used in other L&Fs also so we need to realign it in windows specific class i.e in WindowsIconFactory in paintIcon

Before fix

image

After fix

image

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8373650: Test "javax/swing/JMenuItem/6458123/ManualBug6458123.java" fails because the check icons are not aligned properly as expected (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28889/head:pull/28889
$ git checkout pull/28889

Update a local copy of the PR:
$ git checkout pull/28889
$ git pull https://git.openjdk.org/jdk.git pull/28889/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28889

View PR using the GUI difftool:
$ git pr show -t 28889

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28889.diff

Using Webrev

Link to Webrev Comment

…ls because the check icons are not aligned properly as expected
@bridgekeeper
Copy link

bridgekeeper bot commented Dec 18, 2025

👋 Welcome back psadhukhan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Dec 18, 2025

@prsadhuk This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8373650: Test "javax/swing/JMenuItem/6458123/ManualBug6458123.java" fails because the check icons are not aligned properly as expected

Reviewed-by: tr, dnguyen

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 320 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk
Copy link

openjdk bot commented Dec 18, 2025

@prsadhuk The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@prsadhuk
Copy link
Contributor Author

/touch

@openjdk
Copy link

openjdk bot commented Dec 18, 2025

@prsadhuk The pull request is being re-evaluated and the inactivity timeout has been reset.

@openjdk openjdk bot added the rfr Pull request is ready for review label Dec 18, 2025
@mlbridge
Copy link

mlbridge bot commented Dec 18, 2025

Webrevs

@mrserb
Copy link
Member

mrserb commented Dec 22, 2025

Check/radiobutton icon are not aligned properly in RTL.

What is the proper alignment in this context? The “After fix” image shows that the icons still jump left and right.

Copy link
Contributor

@DamonGuy DamonGuy left a comment

Choose a reason for hiding this comment

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

Any reason why the "After fix" image also has the "Radio button" dot misaligned still?

@prsadhuk
Copy link
Contributor Author

prsadhuk commented Jan 2, 2026

Any reason why the "After fix" image also has the "Radio button" dot misaligned still?

Fixed

image

x + OFFSET,
(icon.getIconHeight() <= 16) ? y + OFFSET : (y + icon.getIconHeight() / 2), state);
} else if (icon.getIconWidth() <= 16) {
if ((c instanceof JMenuItem mi) && mi.getText().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

The condition (c instanceof JMenuItem mi) is always true according to the assert at line 881:

where menuItem is a field in VistaMenuItemCheckIcon, the type of the field is JMenuItem.

This means, you can use menuItem and ignore the passed in parameter c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines 918 to 922
if (icon.getIconWidth() <= 8) {
skin.paintSkin(g,
x + OFFSET,
(icon.getIconHeight() <= 16) ? y + OFFSET : (y + icon.getIconHeight() / 2), state);
} else if (icon.getIconWidth() <= 16) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why painting an icon and check marks / radio bullets in RTL case depends on the width of the icon but there's no such dependency in LTR case.

Shouldn't the performed menu layout handle these cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I see, MenuItemLayout handler's x position calculation for RTL depends on icon rect width

private void calcXPositionsRTL(int startXPos, int leadingGap,
int gap, Rectangle... rects) {
int curXPos = startXPos - leadingGap;
for (Rectangle rect : rects) {
rect.x = curXPos - rect.width;

but LTR doesn't depend on rect width
private void calcXPositionsLTR(int startXPos, int leadingGap,
int gap, Rectangle... rects) {
int curXPos = startXPos + leadingGap;
for (Rectangle rect : rects) {
rect.x = curXPos;

Copy link
Member

Choose a reason for hiding this comment

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

Okay, but why do you have tweak the layout produced by MenuItemLayoutHelper?

Do Metal and Nimbus have to tweak the layout too?

Is it because Windows icons used to be special and combined the icon and check mark / bullet mark, or rather replaced the check mark / bullet mark with the icon? Should we get rid of that special treatment?

I'd like to have answers to these questions.

To be clear, I'm not opposing this approach, it seems to work, yet it seems superfluous, the code kind of repeats calculations. Both Metal and Nimbus L&F have similar column layouts where a separate column is allocated for marks and icons, Windows L&F should re-use that code.

Copy link
Contributor Author

@prsadhuk prsadhuk Jan 16, 2026

Choose a reason for hiding this comment

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

Is it because Windows icons used to be special and combined the icon and check mark / bullet mark, or rather replaced the check mark / bullet mark with the icon? Should we get rid of that special treatment?

I am reusing the VistaMenuItemCheckIcon to render the RadioButtonMenuItem and CheckBoxMenuItem icons and getting rid of the working/treatment made in that class (and rewriting) might result in more regressions which I am avoiding..
There are many factors apart from normal that is affecting the icon position like menuItem.setHorizontalTextPosition(LEADING/TRAILING/LEFT/RIGHT etc), menuItem.setHorizontalAlignment(RIGHT/CENTER etc) which can cause issues like what we are seeing in #28210 which atleast is working now for Windows L&F without any rework.
Metal L&F seems to hardcode the icon position to (0,0) or (2,2)

private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable
{
public void paintOceanIcon(Component c, Graphics g, int x, int y) {
ButtonModel model = ((JMenuItem)c).getModel();
boolean isSelected = model.isSelected();
boolean isEnabled = model.isEnabled();
boolean isPressed = model.isPressed();
boolean isArmed = model.isArmed();
g.translate( x, y );
if (isEnabled) {
MetalUtils.drawGradient(c, g, "RadioButtonMenuItem.gradient",
1, 1, 7, 7, true);
if (isPressed || isArmed) {
g.setColor(MetalLookAndFeel.getPrimaryControl());
}
else {
g.setColor(MetalLookAndFeel.getControlHighlight());
}
g.drawArc(-1, -1, 10, 10, 245, 140);
if (isPressed || isArmed) {
g.setColor(MetalLookAndFeel.getControlInfo());
}
else {
g.setColor(MetalLookAndFeel.getControlDarkShadow());
}
}
else {
g.setColor( MetalLookAndFeel.getMenuDisabledForeground() );
}
g.drawOval(0, 0, 8, 8);

whereas I am reusing the methodology in VistaMenuItemIcon using OFFSET and it seems to work for cases seen till now..

Comment on lines 928 to 936
skin.paintSkin(g,
(type == JRadioButtonMenuItem.class) ? (x + 4 * OFFSET) : (x + 3 * OFFSET),
(icon.getIconHeight() <= 16) ? y + OFFSET : (y + icon.getIconHeight() / 2), state);
}
} else {
if ((c instanceof JMenuItem mi) && (mi.getText().isEmpty() || mi.getAccelerator() != null)) {
skin.paintSkin(g,
(type == JRadioButtonMenuItem.class) ? (x + 3 * OFFSET) : (x + 4 * OFFSET),
(icon.getIconHeight() <= 16) ? y + OFFSET : (y + icon.getIconHeight() / 2), state);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why painting the skin for radio button menu requires such a fix up whereas it's not required for JCheckBoxMenuItem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is taken care via ternary operator, width/spread of check mark is usually more than radio bullet so starting point of checkmark is considered a little ahead compared to radio bullet

Copy link
Member

Choose a reason for hiding this comment

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

I see that it's taken care by the ternary operator. Why is it needed, though?

The skin for both check mark and radio bullet have the same size, and the mark is positioned accordingly inside the rectangle. This works well for the LTR layout, both marks are rendered at the same location and appear aligned in the end. Why does RTL layout treat these marks differently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As told and code shown earlier, the RTL oversees overall rectangle width using all text rect, image icon rect, icon rect etc to calculate icon x position unlike LTR and it seemed a bit off for checkmark as compared to bullet by 1 or 2 pixel or so I catered to it by this logic

Copy link
Contributor

@DamonGuy DamonGuy left a comment

Choose a reason for hiding this comment

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

Although the if/else branches look strange, it works. I don't see a clear way to clean up and condense the conditionals so lgtm unless someone else has an idea.

@DamonGuy
Copy link
Contributor

Also I guess this Copyright year needs to be updated to 2026 now as well.

@aivanov-jdk
Copy link
Member

Although the if/else branches look strange, it works. I don't see a clear way to clean up and condense the conditionals so lgtm unless someone else has an idea.

I haven't looked at the updated code yet.

I wonder why the logic in MenuItemLayoutHelper.java isn't enough, why adjustments are needed.

As I posted in my previous comment, I'm not against this approach as long as it works and fixes the layout, yet I'd like to clean up the code if possible… in a follow-up issue.

@prsadhuk prsadhuk changed the title 8373650: Test javax/swing/JMenuItem/6458123/ManualBug6458123.java fails because the check icons are not aligned properly as expected 8373650: Test "javax/swing/JMenuItem/6458123/ManualBug6458123.java" fails because the check icons are not aligned properly as expected Jan 16, 2026
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 16, 2026
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jan 16, 2026
Copy link
Contributor

@TejeshR13 TejeshR13 left a comment

Choose a reason for hiding this comment

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

Should we update the bugid in test too ?

(type == JRadioButtonMenuItem.class) ? (x + 3 * OFFSET) : (x + 4 * OFFSET),
(icon.getIconHeight() <= 16) ? y + OFFSET : (y + icon.getIconHeight() / 2), state);
} else {
skin.paintSkin(g,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we optimize the code here, since mostly x is changing here based on conditions. It'll help in readability and review too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, y is also changing depending on icon height...
As of now, any more optimization is not possible, it can be done as followup if it is needed..

Copy link
Contributor

Choose a reason for hiding this comment

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

Line 926, 930, 936 and 940 looks same to me. I'm referring to these lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.. optimized..

@TejeshR13
Copy link
Contributor

Should we update the bugid in test too ?

@prsadhuk ?

@prsadhuk
Copy link
Contributor Author

prsadhuk commented Jan 20, 2026

Should we update the bugid in test too ?

@prsadhuk ?

Its in closed...it shouldn't affect this open review but anyway raised a MR

Copy link
Contributor

@TejeshR13 TejeshR13 left a comment

Choose a reason for hiding this comment

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

LGTM

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jan 20, 2026
@prsadhuk
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jan 20, 2026

Going to push as commit e45f565.
Since your change was applied there have been 321 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jan 20, 2026
@openjdk openjdk bot closed this Jan 20, 2026
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jan 20, 2026
@openjdk
Copy link

openjdk bot commented Jan 20, 2026

@prsadhuk Pushed as commit e45f565.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@prsadhuk prsadhuk deleted the JDK-8373650 branch January 20, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

5 participants