Java – how to get int values from a spinner
•
Java
I use NetBeans 7.1 to write Java I have a JFrame. I have a spinner with integer value on it. I want to know how to get the active value in the spinner. I mean the value selected by the user when the program is running; Use it in another way
Solution
spinner. The trick getValue () should do You can convert it to an integer, like
int value = (Integer) spinner.getValue();
Reggoodwin note: you should also call spinner. before calling getValue (). Commitedit() to ensure that the manually entered value is propagated to the model using the editor, otherwise only the old value can be obtained
So it should be the following,
try { spinner.commitEdit(); } catch ( java.text.ParseException e ) { .. } int value = (Integer) spinner.getValue();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码