Java – disable digital grouping in jspinner
•
Java
I need a widget to select TCP / UDP ports, 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 are static constants
I want to remove numeric grouping characters from the result display For example, the default value 55024 is displayed as "55024", and I want it to be "55024" I know the direct numberformat, just as I can use jformattedtextfield. For this purpose, there is a setgrouping used (Boolean) method What does jspinner have? Should I subclass spinnernumbermodel?
Solution
Format the number editor on your spinner:
spinner.setEditor(new JSpinner.NumberEditor(spinner,"#"));
Or more specifically:
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner); editor.getFormat().setGroupingUsed(false); spinner.setEditor(editor);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码