Java Swing - issue in JSpinner

I am developing a Java Desktop application and designing a GUI using the NetBeans Swing GUI Builder.

I want to use JSpinnerin my application. I dragged it and fell on JPanel. Now I want to set two properties:

  • Firstly, it should display numbers in the range of 1 to 50. Not less than 1 or more than 50. How can I set this range?

  • Secondly, when I try to get its value spinner.getValue(), it returns Object. Since my spinner data type is Integer, would it be better to disable it Objectin, Integeror is there any other way to get this numeric value?

+3
source share
5 answers

From here , a way to do this in NetBeans:

  • Create JSpinner just like you.
  • Right-click on it and select "Configure Code"
  • Set initialization as a counter with SpinnerNumberModel .
+1
source

Create a SpinnerNumberModel, this should solve all your problems.

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

For more information, I recommend reading How to Use Spinners

+6
source
int myInt = (Integer)mySpinner.getValue();

Java , spinner , SpinnerNumberModel, Ham.

+1

( 1 50). , , . ( ) swing Object ( ).

0

Swing "" ". Swing.

0

Source: https://habr.com/ru/post/1743046/


All Articles