Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8057791

Selection in JList is drawn with wrong colors in Nimbus L&F

    Details

    • Subcomponent:
    • Introduced In Version:
    • Resolved In Build:
      b127
    • CPU:
      x86
    • OS:
      generic

      Backports

        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 :
        Originally reproduced on MS Windows 8 OS, but should be generic for all supported OSes and not specific to only MS Windows OS.

        A DESCRIPTION OF THE PROBLEM :
        Wrong colors are used for selection foreground (black instead of white) and selection background (light gray instead of dark blue) in JList, when Nimbus L&F is set.
        http://stackoverflow.com/questions/25685269/wrong-colors-in-jlist-when-using-nimbus-and-java-8u20

        REGRESSION :
        Last worked in JDK 8u11.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile, run the provided sample application and select any entry in JList.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The default colors should be used for selected entries in JList.
        ACTUAL -
        Since JDK 8u20 wrong colors are used.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.DefaultListModel;
        import javax.swing.JFrame;
        import javax.swing.JList;
        import javax.swing.SwingUtilities;
        import javax.swing.UIManager;
        import javax.swing.plaf.nimbus.NimbusLookAndFeel;

        public class Test {
            public Test() {
                try {
                    UIManager.setLookAndFeel(new NimbusLookAndFeel());

                    JList<String> l = new JList<>();
                    DefaultListModel<String> model = new DefaultListModel<>();
                    model.add(0, "sssssssss");
                    model.add(1, "sssssssss");
                    model.add(2, "sssssssss");
                    model.add(3, "sssssssss");
                    l.setModel(model);

                    JFrame f = new JFrame();
                    f.setSize(500, 500);
                    f.setLocationRelativeTo(null);
                    f.add(l);
                    f.pack();
                    f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    f.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new Test();
                    }
                });
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        final NimbusLookAndFeel laf = new NimbusLookAndFeel();
        UIManager.setLookAndFeel(laf);
        UIDefaults defaults = laf.getDefaults();
        defaults.put("List[Selected].textForeground",
            laf.getDerivedColor("nimbusLightBackground", 0.0f, 0.0f, 0.0f, 0, false));
        defaults.put("List[Selected].textBackground",
            laf.getDerivedColor("nimbusSelectionBackground", 0.0f, 0.0f, 0.0f, 0, false));
        defaults.put("List[Disabled+Selected].textBackground",
            laf.getDerivedColor("nimbusSelectionBackground", 0.0f, 0.0f, 0.0f, 0, false));
        defaults.put("List[Disabled].textForeground",
            laf.getDerivedColor("nimbusDisabledText", 0.0f, 0.0f, 0.0f, 0, false));
        defaults.put("List:\"List.cellRenderer\"[Disabled].background",
            laf.getDerivedColor("nimbusSelectionBackground", 0.0f, 0.0f, 0.0f, 0, false));

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alitvinov Anton Litvinov
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: