2009-06-23 7 views
0

私はJSpinnerを作成し、カスタムフォーマットでNumberEditorを設定しています。JSpinnerエディタロケール

私が何をしても、フォーマットは "。"を使用します。私のロケール(pt_BR)ではなく、 "、"の代わりに。

priceSpinner = new JSpinner(); 
priceSpinner.setEditor(new JSpinner.NumberEditor(priceSpinner, "0.00")); 

"、"の代わりに "、"を使用できますか。小数点記号として?

答えて

3

カスタムフォーマットパターンを指定することにより、JREにロケールを無視してその特定のフォーマットを使用するように指示します。あなたは絶対にあなた自身のフォーマットパターンを使用する必要がある場合することができます、

JSpinner priceSpinner = new JSpinner(); 
    priceSpinner.setModel(new SpinnerNumberModel(0.00, 0.00, 100.00, 0.01)); 

:あなたは小数点以下2桁の数字のためのスピナー後、単純であれば、あなたのためのNumberEditorを作成する代わりにsetEditorの使ってsetModelを()()を使用そのパターンを作成した後でそのパターンの10進形式のシンボルを調整してください:

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

ありがとうございました。私は本当にカスタムパターンが必要です。なぜなら、 "1"の代わりに "1,00"を必要とするからです。 – tuler

関連する問題