开发者

JTextField: avoid display "," in numbers

开发者 https://www.devze.com 2023-03-14 11:23 出处:网络
I\'m looking for 开发者_开发技巧a better solution than the one I currently have: I have a textfield for which I read and right numbers in:

I'm looking for 开发者_开发技巧a better solution than the one I currently have:

I have a textfield for which I read and right numbers in:

textStiffness.setText((""+stiffness).replaceAll(",", ""));

and

stiffness = Float.valueOf(s1.replaceAll(",", "")).floatValue();

and her you can see my problem and my work around: When I write a number over 999 it adds a "," sign that then can't be read by the Float.value(s) method.

any ideas ?

Jason


If I understood your needs, I think you should use a JFormattedTextField for a clean solution. Have a look at this tutorial .

0

精彩评论

暂无评论...
验证码 换一张
取 消