Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icons in JMenuItems are left aligned #631

Closed
mlaggner opened this issue Dec 30, 2022 · 1 comment
Closed

Icons in JMenuItems are left aligned #631

mlaggner opened this issue Dec 30, 2022 · 1 comment
Milestone

Comments

@mlaggner
Copy link

When using some icons with different widths in JMenuItems, they appear left aligned (see the play icon and the cross at the bottom) :

image

imho they should be centered to make it look more consistent:

image

I found the place where you render the icons: https://github.com/JFormDesigner/FlatLaf/blob/main/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java#L454

you already center the icons vertically:

		// center because the real icon may be smaller than dimension in iconRect
		int y = iconRect.y + centerOffset( iconRect.height, icon.getIconHeight() );

		// paint
		icon.paintIcon( menuItem, g, iconRect.x, y );

but I think you should also center dem horizontally:

		// center because the real icon may be smaller than dimension in iconRect
	        int x = iconRect.x + centerOffset( iconRect.width, icon.getIconWidth() );
	        int y = iconRect.y + centerOffset( iconRect.height, icon.getIconHeight() );

		// paint
		icon.paintIcon( menuItem, g, x, y );

this is what I did for the second screenshot

@DevCharly
Copy link
Collaborator

Thanks for pointing out this issue and for the fix.

Fixed in latest 3.1-SNAPSHOT: https://github.com/JFormDesigner/FlatLaf#snapshots

@DevCharly DevCharly added this to the 3.1 milestone Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants