| Author |
JFormattedTextField
|
Kim Mirtens
Greenhorn
Joined: Dec 17, 2006
Posts: 21
|
|
I have a JFrame with several JFormattedTextFields to get number input from the user. I use the following code to create my JFormattedTextField. JFormattedTextField numberinput = new JFormattedTextField(NumberFormat.getInstance()); My first question is fairly simple: how do I get a number from my JFormattedTextField? I tried to do the following but always got a castException (when I changed the float to double it sometimes works, but I would like to asign the value to a floating point): float input = (Float) numberinput.getValue(); The second question I have is a bit more difficult. I use a JSpinner with a numbermodel, so it actually also uses a JFormattedTextField to display my number values. I want to adjust this JFormattedTextField to always show 3 fraction digits. I use the following code to create my JSpinner: SpinnerNumberModel model = new SpinnerNumberModel(1.000,1.000-0.501,1.000+0.501,0.001); JSpinner spinnumbers = new JSpinner(model);
|
 |
Brian Cole
Author
Ranch Hand
Joined: Sep 20, 2005
Posts: 852
|
|
Originally posted by Tim Pintens: how do I get a number from my JFormattedTextField? I tried to do the following but always got a castException (when I changed the float to double it sometimes works, but I would like to asign the value to a floating point): float input = (Float) numberinput.getValue();
float input = ((Number)numberinput.getValue()).floatValue();
|
bitguru blog
|
 |
Brian Cole
Author
Ranch Hand
Joined: Sep 20, 2005
Posts: 852
|
|
spinnumbers.setEditor(new JSpinner.NumberEditor(spinnumbers, "0.000"));
|
 |
Kim Mirtens
Greenhorn
Joined: Dec 17, 2006
Posts: 21
|
|
|
Thank you very much
|
 |
 |
|
|
subject: JFormattedTextField
|
|
|