This week's book giveaway is in the Other Open Source APIs forum. We're giving away four copies of Storm Applied and have Sean Allen, Peter Pathirana & Matthew Jankowski on-line! See this thread for details.
i am curious about your opinions. there are 2 ways to make a subclass of AbstractColorChooserPanel. you can implement the 5 abstract methods, including buildChooser() which will contain the code that is usually in a constructor. or you can write a constructor AND implements the five abstract methods, but have buildChooser() do nothing. i think i prefer the latter. constructors is where we expect to find this code.
Well, I've checked the Java 7 code of the class, and noticed that it's called from installChooserPanel just after the internal JColorChooser is set. This JColorChooser is used in methods getColorSelectionModel and (indirectly) getColorFromModel. If you need those to build your panel then you must use the buildPanel method.
i am struggling trying to figure this out, but am trying to do it without asking for help. i have seen several examples and they are all "different". i just noticed that one did it one way and another used a constructor instead. it made me curious. since i already started the topic i will post my code and ask for help. this is what i have so far.
no time to post questions since the library is closing
any help appreciated.
the JColorChooser itself works fine, just need help with the custom panel
i figured out i will have to use JColorChooser.createDialog() instead of JColorChooser.showDialog(). that shouldn't be hard. i am having trouble with how to get the Color from the JComboBox to th JColorChooser. it seems to involve getColorSelectionModel().getSelectedColor() and getColorSelectionModel().setSelectedColor(). i am going to post the example that is most like what i am trying to do. i have a few questions about it.
in the code, he has getColorSelectionModel().setSelectedColor(grays[scale.getValue()]); in his methods stateChanged() and actionPerformed(). what happens if the user chooses the custom tab, wants the default setting, so just clicks OK? it looks to me like it does nothing. shouldn't there be a similar line in his constructor for if the user wants the default setting? the other question is more opinion. he has the following code
while i am in favor of not creating objects unless they are needed, i think i would just create one regardless, eliminating the boolean variable and the if statement. i will see what i can do. i would have given AbstractColorChooserPanel a method that returned the selected color rather than this hard to understand ColorSelectionModel stuff
i have made some progress. i think the main gui class is finished. it took only minor changes. i am still having problems with the custom tab though. i added an actionPerformed() but color doesnt change. also i do not understand public void updateChooser(). oops! i forgot to add the listener to the component. it works now but i still dont understand updateChooser().
apparently there is no way to do what i want to do. the default selection of the JComboBox in my custom tab is black. i would like it so when you choose my tab the preview changes to black. i tried this
public void updateChooser()
public void buildChooser()
selector.setSelectedIndex(0); // Default selection is black
the first one disabled all the other tabs. the second didnt do much(not what i wanted anyway). i noticed the other tabs dont change the preview to their defaults(if they have them) either. i guess that is just the way it is. if the user wants to choose Black from my custom tab they will have to drop down the list and choose it even though it is the default