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

JColorChooser - added chooser panels lost on updateComponentTreeUI

    • x86
    • windows_nt, windows_2000, windows_xp

      Name: jk109818 Date: 07/30/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
      Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

      Also occurs on 1.3.

      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If you use SwingUtilities.updateComponentTreeUI(Component c) to update a JColorChooser which has color chooser panels added to it, these added panels are lost, reverting to the default chooser panels.
      This problem is even worse if the default panels are replaced with new chooser panels. If the SwingUtilities.updateComponentTreeUI(Component c) is used after JColorChooser.setColorChooserPanels(), an IllegalArgumentException is thrown.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run both examples provided and observe the behavior.
      Comment out the SwingUtilities.updateComponentTreeUI(frame); line from both examples.
      Run the examples again, and observe the proper behavior.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Both runs should work exactly the same with the updateComponentTreeUI call inserted and removed.
      With ColorChooserBug1, the added panel does not show up after updateComponentTreeUI.
      With ColorChooserBug2, an IllegalArgumentException is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      The following exception is thrown when running ColorChooserBug2:

      java.lang.IllegalArgumentException: chooser panel not in this chooser
      at javax.swing.JColorChooser.removeChooserPanel(JColorChooser.java:409)
      at javax.swing.plaf.basic.BasicColorChooserUI.uninstallDefaultChoosers(BasicColorChooserUI.java:61)
      at javax.swing.plaf.basic.BasicColorChooserUI.uninstallUI(BasicColorChooserUI.java:108)
      at javax.swing.JComponent.setUI(JComponent.java:444)
      at javax.swing.JColorChooser.setUI(JColorChooser.java:209)
      at javax.swing.JColorChooser.updateUI(JColorChooser.java:220)
      at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1100)
      at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1111)
      at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1111)
      at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1111)
      at javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1111)
      at javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1092)
      at ColorChooserBug2.main(ColorChooserBug2.java:28)
      Exception in thread "main"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import javax.swing.colorchooser.AbstractColorChooserPanel;
      public class ColorChooserBug1 {
      public static void main(String[] args) {
      JFrame frame = new JFrame("Test");
      JColorChooser cc = new JColorChooser();
      cc.addChooserPanel(new AbstractColorChooserPanel() {
      public void updateChooser() {
      }
      protected void buildChooser() {
      this.add(new JLabel("This is an added panel"));
      }
      public String getDisplayName() {
      return "Added Tab";
      }
      public Icon getSmallDisplayIcon() {
      return null;
      }
      public Icon getLargeDisplayIcon() {
      return null;
      }
      });
      frame.getContentPane().add(cc);

      // Add & Remove the following line to see the bug in action
      SwingUtilities.updateComponentTreeUI(frame);

      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frame.pack();
      frame.show();
      }
      }
      =============================================================
      import javax.swing.*;
      import javax.swing.colorchooser.AbstractColorChooserPanel;
      public class ColorChooserBug2 {
      public static void main(String[] args) {
      JFrame frame = new JFrame("Test");
      JColorChooser cc = new JColorChooser();
      cc.setChooserPanels(new AbstractColorChooserPanel[] {
      new AbstractColorChooserPanel() {
      public void updateChooser() {
      }
      protected void buildChooser() {
      this.add(new JLabel("This is an added panel"));
      }
      public String getDisplayName() {
      return "Added Tab";
      }
      public Icon getSmallDisplayIcon() {
      return null;
      }
      public Icon getLargeDisplayIcon() {
      return null;
      }
      }
      });
      frame.getContentPane().add(cc);

      // Add & Remove the following line to see the bug in action
      SwingUtilities.updateComponentTreeUI(frame);

      frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      frame.pack();
      frame.show();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1. Add additional chooser panels back after every updateComponentTreeUI call.
      2. Avoid changing L&Fs with added chooser panels on JColorChooser.
      (Incident Review ID: 182792)
      ======================================================================

            malenkov Sergey Malenkov (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: