swingx
  1. swingx
  2. SWINGX-1257

JXColorSelectionButton incorrect colorchooser cancel behavior

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.6.3
    • Component/s: Misc Component
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: Macintosh

    • Issuezilla Id:
      1,257

      Description

      The color chooser dialog in JXColorSelectionButton always remembers the very first color it was called
      with. Lets say your button has a black background. Do this: click the button, dialog opens, select a
      different color, e.g., red, click OK. Now, click the button again, dialog opens, click Cancel. The intended
      behavior is for the background to stay red, but the button color REVERTS back to black.

      The reason is that in JXColorSelectionButton.showDialog the cancel button ActionListener is instantiated
      only once with the final oldColor set to the original background. That oldColor value never changes for
      the actionListener.

      private void showDialog() {
      final Color oldColor = getBackground();

      if (dialog == null) {
      dialog = JColorChooser.createDialog(JXColorSelectionButton.this,
      "Choose a color", true, getChooser(),
      new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent) {
      Color color = getChooser().getColor();
      if (color != null)

      { setBackground(color); }

      }
      },
      new ActionListener() {
      public void actionPerformed(ActionEvent actionEvent)

      { setBackground(oldColor); }

      });
      dialog.getContentPane().add(getChooser());
      getChooser().getSelectionModel().addChangeListener(
      new ColorChangeListener(JXColorSelectionButton.this));
      }

      dialog.setVisible(true);

      }

        Activity

        Hide
        Karl Schaefer added a comment -

        SWINGX-1257: Fixed issue with restoring color when dialog is canceled.

        swingx-core/src/main/java/org/jdesktop/swingx/JXColorSelectionButton.java

        Committed revision 3949.

        Show
        Karl Schaefer added a comment - SWINGX-1257 : Fixed issue with restoring color when dialog is canceled. swingx-core/src/main/java/org/jdesktop/swingx/JXColorSelectionButton.java Committed revision 3949.

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            leuski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: