Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing - Problem in JSpinner

I am developing a Java Desktop Application and designing the GUI with the help of Netbeans Swing GUI builder.

I want to use a JSpinner in my app. I have dragged and dropped it to a JPanel. Now, I want to set its two properties:

  • First, It should display numbers in the range of 1 to 50. Neither less than 1 nor greater than 50. How can I set that range?

  • Second, when I try to get the value of it by spinner.getValue() it returns an Object. As my spinner's data type is Integer, would it be better to downcast the Object into Integer or Is there any other way to get that numeric value?

like image 952
Yatendra Avatar asked Aug 12 '26 14:08

Yatendra


1 Answers

Create a SpinnerNumberModel, this should solve all your problems.

SpinnerNumberModel model =
new SpinnerNumberModel(int initialValue, int minValue, int maxValue, int step)

For further information I recommend reading How to Use Spinners

like image 136
Ham Vocke Avatar answered Aug 14 '26 07:08

Ham Vocke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!