Swing JSpinner编辑器语言环境

Swing JSpinner编辑器语言环境,swing,locale,jspinner,Swing,Locale,Jspinner,我正在创建一个JSpinner,并使用自定义格式设置NumberEditor 但无论我做什么,格式都使用“.”而不是“,”,而不是根据我的区域设置(pt_BR) 是否可以使用“,”而不是“.”作为十进制分隔符?通过指定自定义格式模式,您告诉JRE忽略您的区域设置并使用该特定格式。如果只是在数字微调器后面加上小数点后两位,请使用setModel()而不是setEditor(),这将为您创建一个NumberEditor: JSpinner priceSpinner = new JSpinne

我正在创建一个JSpinner,并使用自定义格式设置NumberEditor

但无论我做什么,格式都使用“.”而不是“,”,而不是根据我的区域设置(pt_BR)


是否可以使用“,”而不是“.”作为十进制分隔符?

通过指定自定义格式模式,您告诉JRE忽略您的区域设置并使用该特定格式。如果只是在数字微调器后面加上小数点后两位,请使用setModel()而不是setEditor(),这将为您创建一个NumberEditor:

    JSpinner priceSpinner = new JSpinner();
    priceSpinner.setModel(new SpinnerNumberModel(0.00, 0.00, 100.00, 0.01));
如果绝对必须使用自己的格式模式,则可以在创建模式后调整该模式的十进制格式符号:

    JSpinner priceSpinner = new JSpinner();
    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(priceSpinner, "0.00");
    DecimalFormat format = editor.getFormat();
    //better to use Locale.getDefault() here if your locale is already pt_BR
    Locale myLocale = new Locale("pt", "BR");
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(myLocale));
    priceSpinner.setEditor(editor);

通过指定自定义格式模式,您告诉JRE忽略您的区域设置并使用该特定格式。如果只是在数字微调器后面加上小数点后两位,请使用setModel()而不是setEditor(),这将为您创建一个NumberEditor:

    JSpinner priceSpinner = new JSpinner();
    priceSpinner.setModel(new SpinnerNumberModel(0.00, 0.00, 100.00, 0.01));
如果绝对必须使用自己的格式模式,则可以在创建模式后调整该模式的十进制格式符号:

    JSpinner priceSpinner = new JSpinner();
    JSpinner.NumberEditor editor = new JSpinner.NumberEditor(priceSpinner, "0.00");
    DecimalFormat format = editor.getFormat();
    //better to use Locale.getDefault() here if your locale is already pt_BR
    Locale myLocale = new Locale("pt", "BR");
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(myLocale));
    priceSpinner.setEditor(editor);

谢谢,成功了。我真的需要自定义模式,因为我想要“1,00”而不是“1”。谢谢,它起作用了。我真的需要自定义模式,因为我想要“1,00”而不是“1”。