質問
JSpinnerを作成し、カスタム形式でNumberEditorを設定しています。
しかし、私が何をしても、フォーマットは"。"を使用します。私のロケール(pt_BR)に従っていない"、quot;の代わりに。
priceSpinner = new JSpinner();
priceSpinner.setEditor(new JSpinner.NumberEditor(priceSpinner, "0.00"));
"、&;を使用することは可能ですか? 「。」の代わりに。小数点区切りとして?
解決
カスタム形式パターンを指定することにより、ロケールを無視してその特定の形式を使用するようにJREに指示します。単に小数点以下2桁までの数字のスピナーを使用している場合は、setEditor()の代わりにsetModel()を使用して、NumberEditorを作成します。
JSpinner priceSpinner = new JSpinner();
priceSpinner.setModel(new SpinnerNumberModel(0.00, 0.00, 100.00, 0.01));
独自のフォーマットパターンを絶対に使用する必要がある場合は、作成後にそのパターンの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);
所属していません StackOverflow