RFR: 8365625: Can't change accelerator colors in Windows L&F

Prasanta Sadhukhan psadhukhan at openjdk.org
Tue Aug 19 03:12:54 UTC 2025


On Mon, 18 Aug 2025 16:31:00 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> **Problem:**
> 
> The colors for the accelerators are cached in static fields: `disabledForeground`, `acceleratorSelectionForeground` and `acceleratorForeground`. As soon as this field is set to a non-`UIResource` value, the value cannot change.
> 
> **Fix:**
> 
> Remove the static fields for accelerator from `WindowsMenuItemUI` and use the fields inherited from `BasicMenuItemUI`, pass these fields as parameters to static methods.
> 
> Additionally, I formatted the calls to `WindowsMenuItemUI.paintMenuItem` in one consistent way.
> 
> I removed the redundant javadoc from `paintMenuItem` and added the missing `@Override` annotation.
> 
> I provided a regression test. The test also reproduces [JDK-8365375](https://bugs.openjdk.org/browse/JDK-8365375) that was resolved in #26743.

test/jdk/com/sun/java/swing/plaf/windows/MenuItem/MenuItemAcceleratorColor.java line 126:

> 124:         Color acceleratorSelectionForeground = UIManager.getColor("MenuItem.acceleratorSelectionForeground");
> 125:         UIManager.put("MenuItem.acceleratorForeground", Color.GREEN);
> 126:         UIManager.put("MenuItem.acceleratorSelectionForeground", Color.RED);

We are testing 2 of 3 static fields..I guess since we do not have test for these fields explicitly, we can test the 3rd one too which is `disabledForeground`

like putting `UIManager.put("MenuItem.disabledForeground", Color.BLUE) `
and do `quit.setEnabled(false)` in which case it should be BLUE

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26826#discussion_r2283953201


More information about the client-libs-dev mailing list