简体   繁体   English

如果语言环境为法语,如何在JSpinner中将浮点符号设置为点而不是逗号?

[英]How to set the floating point symbol in JSpinner to dot instead of comma if the locale is french?

I am making a Java application localized in French. 我正在将Java应用程序本地化为法语。 I used some JSpinner s that accept only a float. 我使用了一些仅接受浮点数的JSpinner

The problem is that the decimal point (the separator between integer part and decimal part) in float numbers is represented by a comma ( , ). 问题在于浮点数中的小数点(整数部分与小数部分之间的分隔符)用逗号( , )表示。 This behavior make a number like 12.34 invalid and the JSpinner reject it, but If I type 12,34 it will be accepted. 此行为使像12.34这样的数字无效,并且JSpinner拒绝它,但是如果我键入12,34 ,它将被接受。

How can I force a JSpinner to use a dot ( . ) as the decimal point and not the comma ? 如何强制JSpinner使用点( . )作为小数点而不是逗号?

The main method begin like this : main方法是这样开始的:

public static void main(String args[]) {
   Locale.setDefault(Locale.FRENCH); // Set French as the application language
   /* ... */
}

I found the solution. 我找到了解决方案。 When you use the method Locale.setDefault(Locale) it sets the default locale for display and also for formatting , but in my case, I need only to display my user interfaces in French. 当您使用方法Locale.setDefault(Locale)它设置了用于显示以及用于格式化的默认语言环境,但就我而言,我只需要用法语显示用户界面即可。 For that, I have to use also the second overload of the method : setDefault(Locale.Category, Locale) , where the first parameter indicate if I want to use the locale for displaying user interfaces or for formatting date, numbers or curencies. 为此,我还必须使用方法的第二个重载: setDefault(Locale.Category, Locale) ,其中第一个参数指示我是否要使用语言环境来显示用户界面或格式化日期,数字或货币。 The main method now is like this : 现在的主要方法是这样的:

Locale.setDefault(Locale.FRENCH); // Display the user interfaces in French
Locale.setDefault(Locale.Category.FORMAT, Locale.ENGLISH); // But the formatting in English

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM