views:

55

answers:

2

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 :

double 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

+1  A: 

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

Number number = (Number)stopAppFormattedTextField.getValue();
double stop = number.doubleValue();
Joonas Pulakka
+4  A: 

Add this to your code after initialization:

stopAppFormattedTextField.setValue(0d);

The getValue will return double auto-magically

nanda