JSpinner with a null value
I need a JSpinner which can be set to null. in older forums, i found this piece of information on how to do it. Can any one elaborate on how to do this?
--------------------------------------------------------------------------------------------
You then just need to extend JSpinner.DateEditor to create an editor that accepts null values:
public class NullDateEditor extends JSpinner.DateEditor
{
public void stateChanged(ChangeEvent e)
{
Object value = getSpinner().getValue();
String text = "None";
if(value != null)
{
text = getFormat().format((Date)value);
}
getTextField().setText(text);
}
}
Then a call to spinner.setEditor(new NullDateEditor()) should hopefully work!
To do the same for numeric values I guess you'd need to extend SpinnerNumberModel and JSpinner.NumericEditor.
Hope this helps.