开发者

Disabling digit grouping in a JSpinner

开发者 https://www.devze.com 2023-03-09 13:10 出处:网络
I needed a widget to select a TCP/UDP开发者_运维知识库 port, so I wrote the following: public static JSpinner makePortSpinner()

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消