2
我需要格式化jformattedtextfeild,以便在运行时只添加带有两个小数位的double/float值。
ex:15600.00
请帮我解决这个问题。谢谢。如何在jformattedtextfield中仅添加double值
我需要格式化jformattedtextfeild,以便在运行时只添加带有两个小数位的double/float值。
ex:15600.00
请帮我解决这个问题。谢谢。如何在jformattedtextfield中仅添加double值
下面是关于如何做到这一点的例子:
NumberFormat format = DecimalFormat.getInstance();
format.setMinimumFractionDigits(2);
format.setMaximumFractionDigits(2);
format.setRoundingMode(RoundingMode.HALF_UP);
JFormattedTextField myTwoDecimalTextfield = new JFormattedTextField(format);
myTwoDecimalTextfield.setValue(new Float(3.14));
[如何使用格式化的文本栏(http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html) 。请记住,'JFormattedTextField'是post验证的,它不会对输入进行实时验证。 – MadProgrammer 2014-11-21 07:55:13
谢谢你@MadProgrammer – 2014-11-21 08:00:03
考虑使用'SpinnerNumberModel'而不是'JFormattedTextField'来使用'JSpinner'。 – 2014-11-21 08:05:36