0

I am trying to make a JSpinner with a set of values which step less and less as they decrease, so I created a function to generate these values and I add 100 values to a list, then try to create a SpinnerListModel with the list as it's source. This gives the following error:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid sequence element
    at javax.swing.SpinnerListModel.setValue(SpinnerListModel.java:185)
    at com.fractalexplorer.main.RangeSelector.setValue(RangeSelector.java:106)

Here is the relevant code:

SpinnerListModel spinnerModel = new SpinnerListModel(constructSpinnerModelSource());

public List<Double> constructSpinnerModelSource()
{
    List<Double> list = new ArrayList<Double>();
    int steps = 100;

    for(int i = 0; i <= steps; i++)
        list.add(getStep(i));

    return list;
}

public Double getStep(double x)
{
    return 2.25 * Math.pow(0.95, x);
}

The values range from 2 to 0.013321190745751494 currently, here are the last 12 values:

0.02341981115445541, 0.022248820596732638, 0.021136379566896003, 
0.020079560588551204, 0.01907558255912364, 0.018121803431167458,    
0.017215713259609085, 0.01635492759662863, 0.015537181216797197, 
0.014760322155957337, 0.01402230604815947, 0.013321190745751494
mKorbel
  • 109,525
  • 20
  • 134
  • 319
mbdavis
  • 3,861
  • 2
  • 22
  • 42

2 Answers2

2

This exception is thrown if you try to set a value that does not belong in the JSpinner's list of values.

Example:

String[] values = {"one", "two", "three", "four"};
SpinnerModel model = new SpinnerListModel(values);
model.setValue("TWO"); // throws IllegalArgumentException
brunobastosg
  • 1,380
  • 19
  • 31
1

You have list of Double items but try to set value to RangeSelector instance.

Either try to add RangeSelector instances to the model or cast the range to Double when calling setValue(). In fact you try to set value which is not in the list and model can't accept the value.

StanislavL
  • 56,971
  • 9
  • 68
  • 98