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

BasicColorChooserUI ignores JColorChooser selection model changes

XMLWordPrintable

    • b27
    • x86
    • windows_xp
    • Not verified

      FULL PRODUCT VERSION :
      1.6.0-beta-b59

      A DESCRIPTION OF THE PROBLEM :
      If you call JColorChooser#setSelectionModel the color chooser doesn't show a preview anymore. BasicColorChooserUI registers a listener for updating the preview panel only with the initial selection model, but doesn't reregister this listener if the color chooser's selection model changes.

      BasicColorChooserUI has a property change handler that should listen to the JColorChooser's property JColorChooser.SELECTION_MODEL_PROPERTY.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Construct a JColorChooser
      JColorChooser colorChooser = new JColorChooser(Color.RED);

      2) Change the selection model.
      colorChooser.setSelectionModel(new DefaultColorSelectionModel(Color.WHITE));

      3) Display the color chooser, e.g.
      JDialog dialog = JColorChooser.createDialog(null, "Choose", true, colorChooser, null, null);
      dialog.show();

      4) Choose a color.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After step 3, the preview panel should display WHITE, not RED.
      After step 4, the preview shall display a preview of the selected color.
      ACTUAL -
      After step 3, the preview panel displays RED.
      When choosing a color, the preview panel displays RED.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.Color;

      import javax.swing.JColorChooser;
      import javax.swing.JDialog;
      import javax.swing.colorchooser.DefaultColorSelectionModel;

      public class BasicColorChooserUIBug {
          
          public static void main(String[] args) {
              JColorChooser colorChooser = new JColorChooser(Color.RED);
              colorChooser.setSelectionModel(new DefaultColorSelectionModel(Color.WHITE));
              JDialog dialog = JColorChooser.createDialog(null, "Choose", true, colorChooser, null, null);
              dialog.show();
          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1) Don't use JColorChooser#setSelectionModel. Use only JColorChooser(ColorSelectionModel)

      2) Use a look&feel that fixes the bug, i.e. that listens to changes of the color selection model to reregister the preview listener.

            malenkov Sergey Malenkov (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: