import java.awt.*; 
import javax.swing.*; 

class NimbusJListSelectionColor { 
    public static void main(String[] args) { 
        SwingUtilities.invokeLater(() -> { 
            try { 
                UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); 
            } catch (Exception checkedExceptionsPleaseDie) { 
                throw new RuntimeException(checkedExceptionsPleaseDie); 
            } 
             
            JFrame frame = new JFrame(); 
            frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE); 
            frame.setLayout(new GridLayout(1, 0)); 
             
            JList<String> list1 = new JList<>(); 
            JList<String> list2 = new JList<>(); 
            JList<String> list3 = new JList<>(); 
            list1.setListData(new String[] { "One", "Two", "Three" }); 
            list2.setListData(new String[] { "One", "Two", "Three" }); 
            list3.setListData(new String[] { "One", "Two", "Three" }); 
            list1.setSelectedIndex(0); 
            list2.setSelectedIndex(0); 
            list3.setSelectedIndex(0); 
            frame.add(new JScrollPane(list1)); 
            frame.add(new JScrollPane(list2)); 
            frame.add(new JScrollPane(list3)); 
             
            // list1 is not customized; the selection color is correct as configured by Nimbus, white on blue 
             
            // list2 has overridden the list cell renderer; 
            // on its own, this should not change the color, and didn't used to in older Java versions, 
            // but now the selection color is now black on light gray 
            list2.setCellRenderer(new DefaultListCellRenderer() { 
                @Override 
                public Component getListCellRendererComponent( 
                        JList<?> list, 
                        Object value, 
                        int index, 
                        boolean isSelected, 
                        boolean cellHasFocus) { 
                     
                    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 
                } 
            }); 
             
            // list3 contains a workaround; the selection color is correct again 
            list3.setCellRenderer(new DefaultListCellRenderer() { 
                @Override 
                public Component getListCellRendererComponent( 
                        JList<?> list, 
                        Object value, 
                        int index, 
                        boolean isSelected, 
                        boolean cellHasFocus) { 
                     
                    super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 
                     
                    // this print statement shows the correct color, as it is configured, and as it should appear: 
                    // 57,105,138 a.k.a. #39698A (blue) 
                    // but the configured color is ignored; what is drawn on screen is: 
                    // 214,217,223 a.k.a. #D6D9DF (light gray) 
                    if (isSelected) { 
                        System.out.println(this.getBackground()); 
                    } 
                     
                    // this workaround bypasses the bug by creating a non-UIResource Color instance: 
                    this.setBackground(new Color(this.getBackground().getRGB(), true)); 
                    this.setForeground(new Color(this.getForeground().getRGB(), true)); 
                     
                    return this; 
                } 
            }); 
             
            frame.pack(); 
            frame.setLocationRelativeTo(null); 
            frame.setVisible(true); 
        }); 
    } 
} 