JDK-8067280 : Wrong JList selection colors used in Nimbus L&F
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u20
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-09-08
  • Updated: 2014-12-11
  • Resolved: 2014-09-08
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
When using the Nimbus look & feel, the selected item in a JList is not marked in the list's (default) selection foreground/background colors.
By default, the selection foreground and background colors of a JList in Nimbus should be #FFFFFF (white) and  #39698A (a dark blue), respectively. However, the text color of the selected item does not change (i.e. remains black), and it is marked in #D6D9DF (a light grey).

REGRESSION.  Last worked in version 8u11

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Set the NimbusLookAndFeel for your application, and make a JList visible on the screen (containing some items). Select any item.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The selected item is marked in the selection background color of the JList. Its text is shown in the selection foreground color of the JList.
ACTUAL -
The selected item is marked in some other color. Its text is shown in the default text color.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.time.Month;

import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

public class SelectionBackgroundTestApplication
{
    
    public static void main( String[] args )
    {
        try
        {
            UIManager.setLookAndFeel( new NimbusLookAndFeel() );
        }
        catch ( UnsupportedLookAndFeelException e )
        {
            e.printStackTrace();
            return;
        }
        
        JDialog dlg = new JDialog();
        dlg.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
        
        JList<Month> comp = new JList<>( Month.values() );
        System.out.println( "Expected selection foreground color: #" + Integer.toHexString( comp.getSelectionForeground().getRGB() ) );
        System.out.println( "Expected selection background color: #" + Integer.toHexString( comp.getSelectionBackground().getRGB() ) );
        
        dlg.getContentPane().add( comp );
        dlg.pack();
        dlg.setVisible( true );
    }
    
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Setting the selection foreground and background colors of the JList to copies of the original selection foreground and background colors, respectively, fixes the problem:

        comp.setSelectionForeground( new java.awt.Color( comp.getSelectionForeground().getRGB() ) );
        comp.setSelectionBackground( new java.awt.Color( comp.getSelectionBackground().getRGB() ) );