JDK-8041725 : Nimbus JList selection colors persist across L&F changes
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u45,7-pool,8-pool,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows
  • Submitted: 2013-11-20
  • Updated: 2014-10-29
  • Resolved: 2014-05-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u76Fixed 8u20Fixed 9Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
JDK 7u45 b18, JDK 9, JDK 8

A DESCRIPTION OF THE PROBLEM :
The selectionBackground and selectionForeground colors installed on a JList by the Nimbus L&F are instances of javax.swing.plaf.nimbus.DerivedColor, which does not implement UIResource. Consequently, if the Nimbus L&F has been used, these colors then incorrectly persist when switching to another L&F.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
As a workaround, override the JList's updateUI method as follows:

@Override
public void updateUI() {
setSelectionBackground(new javax.swing.plaf.ColorUIResource(0));
setSelectionForeground(new javax.swing.plaf.ColorUIResource(0));
super.updateUI();
}
Comments
It was defined that a reason of this bug in JDK 9 is explicit declaration of the colors "textForeground", "textBackground" as colors not implementing "javax.swing.plaf.UIResource" interface for various styles of "javax.swing.JList" component in the file "jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf" by usage of "uiResource="false"" attribute/value pairs. A possible solution: Removal of "uiResource="false"" attributes from the tags declaring the selection colors of "JList" component in "jdk/src/share/classes/javax/swing/plaf/nimbus/skin.laf" file allows to make these colors instances of "javax.swing.plaf.nimbus.DerivedColor.UIResource" class implementing "javax.swing.plaf.UIResource" interface, what resolves the bug.
15-05-2014

The bug was reproduced with JDK 9 b09, JDK 8u5 b13, JDK 7u55 b13 by means of the attached test case "JListColorsDoNotImplUIResourceInNimbus.java".
24-04-2014

The test case was created and attached to the bug record as the file "JListColorsDoNotImplUIResourceInNimbus.java".
24-04-2014