I needed a widget to select a TCP/UDP port, so I wrote the following:
public static JSpinner makePortSpinner()
{
final JSpinner spinner = new JSpinner(
new SpinnerNumberModel( DefaultPort, 1024, 65535, 1 ) );
spinner.setFont( Monospaced );
return spinner;
}
...Monospaced
and DefaultPort
being static constants.
I would like to remove the digit grouping characters from the resulting display. For example, the default of 55024 displays as "55,024", where I would like it to be "55024". I know that straight NumberFormat
, as I might use with JFormattedTextField
, has a setGroupingUsed(boolean)
method for this purpose. Is there anything like this for JSpinner
? Should I subclass SpinnerNumberModel
?
Set the format of the number editor on your spinner:
spinner.setEditor(new JSpinner.NumberEditor(spinner,"#"));
or to be more explicit:
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner);
editor.getFormat().setGroupingUsed(false);
spinner.setEditor(editor);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With