On Thu, 15 Oct 2026 06:55:22 GMT, Prasanta Sadhukhan <[email protected]> wrote:
>> [JDK-8348760](https://bugs.openjdk.org/browse/JDK-8348760) fixed an issue in >> Windows L&F JMenuItem layout whereby radio bullet/checkmark was rendered in >> different columnspace than menuitem imageicon so radiobullet/checkmark is >> rendered in first column and imageicon is rendered in 2nd column but this >> rendering of imageicon in 2nd columnspace was done invariably for all >> JMenuItem irrespective of if it is JRadioButtonMenuItem or JCheckBoxMenuItem >> or JMenuItem, which is wrong. >> >> Normal JMenuItem (which are not JRadioButtonMenuItem or JCheckBoxMenuItem) >> imageicon rendering should be done in first columnspace as was done before >> JDK-8348760 fix because there is no radiobullet/checkmark to render for >> those menuitems so no need to reserve columnspace for those bullet/checkmark >> icon >> >> Before fix >> >> <img width="205" height="127" alt="image" >> src="https://github.com/user-attachments/assets/13a1e352-5e8d-4251-b7a7-032935eab74e" >> /> >> >> >> After fix >> >> <img width="195" height="131" alt="image" >> src="https://github.com/user-attachments/assets/84ec3ee6-2823-4bf7-840d-b53f2e9d44c3" >> /> >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Prasanta Sadhukhan has updated the pull request incrementally with one > additional commit since the last revision: > > Review comment fix PR updated to include fixes of review comment..It's been tested with test/jdk/javax/swing/JMenuItem/TestRadioAndCheckMenuItemWithIcon.java <img width="820" height="402" alt="image" src="https://github.com/user-attachments/assets/7df557de-c7e9-490d-8c98-8b9e5de7cfd5" /> <br>test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java <img width="378" height="612" alt="image" src="https://github.com/user-attachments/assets/30aa5169-97c6-4ce4-a8e7-56b27e917c47" /> <br>test/jdk/javax/swing/JMenuItem/LargeMenuTextArrowIconPosition.java <img width="550" height="274" alt="image" src="https://github.com/user-attachments/assets/5b2e85e7-f93c-4c49-a342-2a6f5b25783a" /> <br>standalone RadioIconTest.java <img width="459" height="238" alt="image" src="https://github.com/user-attachments/assets/26d77a7c-f40b-4723-a5ed-f605c2c70560" /> and CI tests Updated PR does - Corrected the combined icon’s reported width - The width now includes the check/bullet mark column offset, image width, and trailing padding. This ensures layout reserves the space actually used by painting and prevents text from overlapping the image as reported in https://github.com/openjdk/jdk/pull/29730#discussion_r3692882358 and also solves popup width increase as reported in https://github.com/openjdk/jdk/pull/29730#discussion_r3692907255 - Made sizing and painting use the same column decision - Both getIconWidth() and paintIcon() uses shared image-offset calculation. Ordinary menu items with images also reserve the correct width when their popup requires separate mark and image columns - Removed the additional text-spacing and extra popup-width adjustment Removed the static textGap, the extra menu-item preferred-width adjustment, and allocateIconTextGap with its LTR/RTL text shifts in MenuItemLayoutHelper Removed the additional 2 * afterCheckIconGap added in WindowsPopupMenuUI.getPreferredSize(). The correctly reported icon widths already contribute the required space - Changed the scan and cached result from top-level-menu scope to individual-popup scope Each JPopupMenu now determines its own column arrangement. A checkbox/radio item with an image in a submenu no longer affects its parent or sibling popups - Removed recursive scanning scanMenuForCheckBulletAndIcon() and findTopLevelMenu() The updated scan examines only the popup’s direct, visible children. Each menu item reads the cached result from its immediate parent popup. This also supports standalone context menus without a top-level JMenu - Moved scanning from painting to sizing/layout A Windows-specific DefaultMenuLayout subclass computes the popup’s decision before measuring children and refreshes it during layout. This avoids using stale or uninitialized information when calculating preferred sizes - Preserved the requirement that one item must contain both the mark and image. Separate columns are requested when a visible checkbox/radio menu item itself has an icon. A check-only item and a separate ordinary image-only item do not trigger that arrangement. Selection state does not affect space reservation. - Refreshes layout information after menu changes Subsequent sizing/layout passes accounts for added or removed icons, visibility changes, and changed popup contents. Existing column-width and child-size caches are refreshed through DefaultMenuLayout. - Updated RTL checkmark/bullet and image placement The check/bullet mark is mirrored within the same rectangle using its actual theme skin width and the image is also positioned relative to the combined icon rectangle’s right edge, keeping it within the reported bounds instead of painting to the left of its allocated area - Added lifecycle handling for the popup cache The cached decision is cleared when the Windows popup UI is uninstalled. The Windows layout replaces only null or UI-provided layouts, preserving application-installed layouts. - Updated test Test is made to execute in system L&F(Windows L&F by default) to ensure the bug fix is tested Also, made to run in metal and nimbus in all platforms ------------- PR Comment: https://git.openjdk.org/jdk/pull/29730#issuecomment-6186506218
