use Locale.FRENCH with "." decimal separator instead of ","
hi,
i need to change the decimal separator to "." for the whole application when the Locale is French. (i don't want to change the locale because of date and ok cancel button labels etc...)
i though the call DecimalFormatSymbols.getInstance().setDecimalSeparator('.');
would change the decimal for the whole application but it doesn't.
here is a little test case
//display a JSpinner with Locale.US we have the "." separator it's ok
Locale.setDefault(Locale.US);
JSpinner spinner =new JSpinner(new SpinnerNumberModel(1.1d,null,null,1d));
JOptionPane.showInputDialog(spinner);
Locale.setDefault(Locale.FRENCH);
//i though it would change the symbol for the default instance so also for all jvm
DecimalFormatSymbols.getInstance().setDecimalSeparator('.');
//display a JSpinner with Locale.FRENCH we have the "," separator it's not ok so previous line don't work
JSpinner spinner2 =new JSpinner(new SpinnerNumberModel((Double)spinner.getValue(),null,null,1d));
JOptionPane.showInputDialog(spinner2);
i will appreciate any help.
thank you
Julien Blaize
# 1
>
> DecimalFormatSymbols.getInstance().setDecimalSeparator
> ('.');
> //display a JSpinner with Locale.FRENCH we have the
> "," separator it's not ok so previous line don't
> work
> JSpinner spinner2 = new JSpinner(new
> SpinnerNumberModel((Double)spinner.getValue(),null,nul
> l,1d));
> JOptionPane.showInputDialog(spinner2); [/code]
>
You figured out how to change the separator, but you promptly threw away the DecimalFormatSymbols object without using it.
JSpinners have "Editors". You want to look at the JSpinner.NumberEditor probably, and most likely you will want to find a way to provide your own number format for the JFormattedTextField that it uses to display numbers.
Regards,
John O'Conner
# 2
First of all thank you for the reply.
i understand now that i am able to change the way a single JSpinner will use the decimal symbols.
but i want to change he behaviour for all the application including other component.
is there a way to derive the french locale (or create a locale) so the decimal separator will be "." instead of ", " by default for all call to NumberFormat.getInstance(). Like having the behaviour of the french locale for the application except for the DecimalFormat tha will be like the in the US locale.