On Thu, 19 Feb 2026 02:52:26 GMT, Prasanta Sadhukhan <[email protected]> 
wrote:

> If JFrame's window decorations is provided by the Metal LookAndFeel then 
> system menu icon (e.g., which shows Restore, Minimize, Maximize, and Close 
> menu options when clicked) does not activate when clicked on the right edge 
> of the icon
> 
> MetalTitlePane creates a JMenuBar with a system menu icon and a JMenu when 
> clicked on it. This JMenu is created by
> `MetalTitlePane.createMenu`  in the title bar with an empty string and 
> zero-width string doesn't cover the systemmenu icon to activate the menu when 
> clicked on right edge of the icon. Changing the text of the JMenu to a 
> non-zero width character properly sizes the menu button covering and 
> activating the system menu icon even when clicked on right edge i.e anywhere 
> in the icon.
> 
> Without fix
> <img width="246" height="127" alt="image" 
> src="https://github.com/user-attachments/assets/f872bd95-ea15-4245-9c88-f06834804e9b";
>  />
> 
> With fix
> <img width="190" height="134" alt="image" 
> src="https://github.com/user-attachments/assets/f79e8e96-0c71-49e0-9501-5b3a12bbcd83";
>  />

When frame is made visible, the layouting is done and 
`BasicMenuItemUI.getPreferredMenuItemSize` called from 
`BasicMenuUI.getMaximumSize`, is called which does some calculations and 
returns menu width to 9 for zero text-length`JMenu`
 which is why popup is visible even when clicked on middle of system icon, 
which is of `16x16` size, for even zero-text-length JMenu but not at the right 
edge.
 For non-zero text's JMenu, `getPreferredMenuItemSize()` returns menu width to 
15 so popup is visible when clicked on right edge of icon 
 Since the preferred width is getting updated while layouting if not specified 
initially, its better to set the preferred width upfront to image icon size
 so that whole icon area is activated for popup menu, so both left and right 
edge will work, therefore I have updated the PR accordingly..

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

PR Comment: https://git.openjdk.org/jdk/pull/29808#issuecomment-3963635107

Reply via email to