开发者

fetching float values from jformatted text field

I am able to create JFormatted TextField that accepts only float values,but I am not able to fetch that value.... I am declaring it ..

stopAppFormattedTextField = new javax.swing.JFormattedTextField(new DecimalFormat("#.00"));

and fetching the value using :

doubl开发者_高级运维e stop=(Double)stopAppFormattedTextField.getValue();

but the above statement is throwing the following exception:

"Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Double"

what should I do to fetch float values? -Thanks in advance


You're getting Longs from the formatter, but you want doubles. You can do this:

Number number = (Number)stopAppFormattedTextField.getValue();
double stop = number.doubleValue();


Add this to your code after initialization:

stopAppFormattedTextField.setValue(0d);

The getValue will return double auto-magically

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜