In my application some values internally have their range from 0. But user should see this range starting from 1. I thought it would be appropriate to move this offseting stuff into presentation. In this case it is JSpinner component. So that I could specify in contructor if there is an offset (not all values have it). But if I override getValue()
of JSpinner or getValue()
of model to be something like that (+1 is just for test)
public Object getValue() {
Number value = (Number)super.getValue();
Number newValue=value;
if (value instanceof Double){
newValue=value.doubleValue()+1;
}
else if (value instanceof Integer){
newValue = value.intValue()+1;
}
return newValue;
}
it goes into infinite loop. I guess, it fires state change event for some reason here. Calls getValue
again, increments more, fires event, increments and so on.
How could this be solved? Thanks