[SWINGX-1257] JXColorSelectionButton incorrect colorchooser cancel behavior Created: 21/Jan/10  Updated: 10/Mar/11  Resolved: 10/Mar/11

Status: Resolved
Project: swingx
Component/s: Misc Component
Affects Version/s: 1.6.1
Fix Version/s: 1.6.3

Type: Bug Priority: Major
Reporter: leuski Assignee: Karl Schaefer
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
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);

}



 Comments   
Comment by Karl Schaefer [ 10/Mar/11 ]

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

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

Committed revision 3949.

Generated at Mon Sep 26 02:50:48 UTC 2016 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.