kirill-grouchnikov/radiance

Selecting "Choose only web-safe colors" makes it impossible to re-open the JColorChooser panel.

ed-erwin-tf opened this issue · 0 comments

Radiance 7.0.2, Theming, Java 11, Windows 10

In the HTML Sliders color chooser, selecting "Choose only web-safe colors" can make it impossible to re-open that color chooser dialog after it is closed.

You can reproduce the problem like this:

  1. call JColorChooser.showDialog(null, "Pick a color", Color.yellow);
  2. user selects "HTML Sliders" and selects "Choose only web-safe colors".
  3. user selects "OK"
  4. again call JColorChooser.showDialog(null, "Pick a color", Color.yellow);

The color chooser will not open the second time. A stack trace is logged.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "org.pushingpixels.radiance.theming.internal.contrib.randelshofer.quaqua.colorchooser.HTMLColorSliderModel.setWebSaveOnly(boolean)" because "this.ccModel" is null
	at org.pushingpixels.radiance.theming.internal.contrib.randelshofer.quaqua.colorchooser.HTMLChooser.webSaveChanged(HTMLChooser.java:414)
	at java.desktop/javax.swing.AbstractButton.fireItemStateChanged(AbstractButton.java:2000)
	at java.desktop/javax.swing.AbstractButton$Handler.itemStateChanged(AbstractButton.java:2320)

The bug is in incorrect code for initializing the HTMLChooser class.

  1. The method initComponents(), called from the constructor, adds a listener to the webSaveCheckBox.
  2. The constructor calls webSaveCheckBox.setSelected(lastWebSaveSelectionState);
  3. An event calls webSaveChanged()
  4. It tries to call ccModel.setWebSaveOnly(), but the variable ccModel is still null.

There are multiple ways to fix this. A simple one is to modify the constructor to make sure that the ccModel is constructed prior to modifying the value of webSaveCheckBox.setSelected().