RFR: 8348760: RadioButton is not shown if JRadioButtonMenuItem is rendered with ImageIcon in WindowsLookAndFeel [v24]

Phil Race prr at openjdk.org
Tue May 27 23:13:00 UTC 2025


On Wed, 12 Mar 2025 11:00:30 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> When JRadioButtonMenuItem is called with imageIcon, then only imageIcon is shown without radiobutton in WIndowsLookAndFeel as there was no provision of drawing the radiobutton alongside icon.
>> If icon is not there, the radiobutton is drawn. Added provision of drawing the radiobutton windows Skin even when imageIcon is present.
>
> Prasanta Sadhukhan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Review comments fix

> I checked rbma.cpp output where I think we can only support the 4th item in the list (which is this) ![image](https://private-user-images.githubusercontent.com/43534309/447489844-32067d1a-8ab2-444c-8db3-265f0e64f6ec.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDgzODU5OTgsIm5iZiI6MTc0ODM4NTY5OCwicGF0aCI6Ii80MzUzNDMwOS80NDc0ODk4NDQtMzIwNjdkMWEtOGFiMi00NDRjLThkYjMtMjY1ZjBlNjRmNmVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTI3VDIyNDEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWVmN2Q3MTJmMGNhNWM5YzE4MWI5YjMxNDYwYmQ1MWJiNmJjY2VjMzI4M2I2YTQwNTI5ZDUwYWE4MDNlMzA0N2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.IKs2UKVCkF23JhYXnMGG5D78UdFV8o974fA74X6zelk)
> 
> This is because we have [JRadioButtonMenuItem](https://docs.oracle.com/en/java/javase/24/docs/api/java.desktop/javax/swing/JRadioButtonMenuItem.html#%3Cinit%3E(java.lang.String,javax.swing.Icon,boolean))([String](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/lang/String.html) text, [Icon](https://docs.oracle.com/en/java/javase/24/docs/api/java.desktop/javax/swing/Icon.html) icon, boolean selected) API which only supports one icon image (so checked/unchecked icon image **in addition** to item icon as below image is not possible in my opinion in Java swing)


Not sure I know what you mean by 4th item, but clearly we aren't going to add an API to supply checked/unchecked images.
But we should support *rendering* like you show above. 
- app supplies icon image and text, WE supply the radio button.
- 
> 
> ![image](https://private-user-images.githubusercontent.com/43534309/447492462-581f4e36-6b55-4a1c-8a5a-465741e43858.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDgzODU5OTgsIm5iZiI6MTc0ODM4NTY5OCwicGF0aCI6Ii80MzUzNDMwOS80NDc0OTI0NjItNTgxZjRlMzYtNmI1NS00YTFjLThhNWEtNDY1NzQxZTQzODU4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTI3VDIyNDEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU5ZmFiYmZmYzUyN2NlYTQyMTg2NTZkYjM3YjI5YmU5OTViOTllY2E0YTRkOWFhM2U5ZDhjNGNmZGU5NTNiZjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.HndjszTSwBDh3V39rS-aoDZI8G6JEsxOAxn95BSpFIA)
> 
> The current state of PR supports this 4th item. 

What is "this 4th item" ?  You mean the case of image + text from app, and WE display a radio button checked ?

Only thing different is when there is no imageicon and menuitem is selected, then the text seems to be in same vertical line as the other items (in native rbma output) ![image](https://private-user-images.githubusercontent.com/43534309/447490318-897f3277-df2e-4827-8381-e51ad8007251.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDgzODU5OTgsIm5iZiI6MTc0ODM4NTY5OCwicGF0aCI6Ii80MzUzNDMwOS80NDc0OTAzMTgtODk3ZjMyNzctZGYyZS00ODI3LTgzODEtZTUxYWQ4MDA3MjUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTI3VDIyNDEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTNhNjM1MTU5OTg1Njc0ZTNlOGI3NmQ1MDU0Y2EzYjUyNzM0ZTQ5ZjI2NmQyYzFmMWM1OTViNjEwZGY2MmExY2QmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.NJqfKGrADw05FVzfOtTbNoHLr8w3WsUNv98kf8GaHaM)
> 
> but current PR the text is shifted to left (when there is no imageicon ie 3rd item in list) and occupies icon space, as below !

If you mean windows always lines up the start of the text, that seems to be true.
So we should do the same.

[image](https://private-user-images.githubusercontent.com/43534309/447504446-43fb1ccc-b475-4147-8131-22f2fc918375.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDgzODU5OTgsIm5iZiI6MTc0ODM4NTY5OCwicGF0aCI6Ii80MzUzNDMwOS80NDc1MDQ0NDYtNDNmYjFjY2MtYjQ3NS00MTQ3LTgxMzEtMjJmMmZjOTE4Mzc1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTI3VDIyNDEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg3NTVkZmM3OWM4NTI1Zjg3ZTI4NTg1MmNlMTc2NDZkYmM4YmQ4MTk4MWFkMDkwYTQyYjMwZDNhNWIyNDQ5NjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.vyGdZfku-sAx05JjUijTBsjXg9BWoIjjwUe3x6CMxcM)
> 
> This is because in most cases (and in SwingSet2) the radiomenu items are drawn without imageicon and there is no extra space between radio bullet and menu text

it seems to me that if there's an image in ANY menu item, Windows reserves the space in all items, hence getting the text aligned.
It just does the funky thing of moving where it displays the item image if there's no checked image.

> 
> ![image](https://private-user-images.githubusercontent.com/43534309/447499626-c5cd5840-d58e-4456-8217-cf7f3ba9bb4e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDgzODU5OTgsIm5iZiI6MTc0ODM4NTY5OCwicGF0aCI6Ii80MzUzNDMwOS80NDc0OTk2MjYtYzVjZDU4NDAtZDU4ZS00NDU2LTgyMTctY2Y3ZjNiYTliYjRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTA1MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwNTI3VDIyNDEzOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTVjOTNiZDc3YWY5ZDZlMjZhOTFmODg1NjkxZGFlMDk2YzE2OGY3ODdhOGY2MjQxNzU5MDNkNWFmYjY0Y2QxNjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.yDEGF7-fRybLIyfHX1AnEqL-76nHD-b17g3p-9xmShg)
> 
> so if we cater to text shifting to same vertical line, there will be difference in behavior w.r.t existing one and user will notice a shift in text to accomodate non-existing image icon)

You mean user will notice text is now aligned ? I think that's fine.
> 
> but it is fixable, so if we are in consensus about supporting the 4th item in rbma.cpp output in Java swing with text in same vertical offset, then let mw know..Anything else in addition needs discussion whether we can support...

I hope (!) we are on the same page. Let me try and say it so we are ..
- WE will always draw a check (tick)  or radio button to show the selected item
- WE will always reserve space for that tick
- WE will never over-write the check/tick with the icon image.
- Icon images will never move  (unlike the funky windows case which is the root of all of this)  because we will always reserve space for it.
- If ANY item has an icon image, ALL items reserve the space, even if not used, this is needed for the next item :
- Text strings will all align. Always

-------------

PR Comment: https://git.openjdk.org/jdk/pull/23324#issuecomment-2914400828


More information about the client-libs-dev mailing list