I’m currently creating a GUI in NetBeans and I have a JSpinner that contains a list of colors, but I’m not sure how to make the text the corresponding color of each one.
I.E. – Red (should be colored red, etc.)
Below is the code so far for the JSpinner:
Color_Selector_Spinner = new javax.swing.JSpinner();
Color_Selector_Spinner.setModel(new javax.swing.SpinnerListModel(new String[] { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"}));
You need the following to make a color-coded
JSpinner:A
ChangeListenerfor theJSpinnerto update the colors when the component value changesA translation of the
Stringvalue into a Color.There is only one
JTextFieldused in the spinner so it must be updated with current color on every change event.