JSpinner is a part of javax.swing package . JSpinner contains a single line of input which might be a number or a object from a ordered sequence . The user can manually type in a legal data into the text field of the spinner . The spinner is sometimes preferred because they do not need a drop down list . Spinners contains a upward and a downward arrow to show the previous and the next element when it is pressed.
Constructors of JSpinner are:
- JSpinner() : Creates an empty spinner with initial value set to zero and no contraints
- JSpinner( SpinnerModel model)
creates a spinner with a specified spinner model passed as argument .
- SpinnerListModel(List l) : creates a spinner model with elements of list l . This spinner model can be used to set as a model for spinner.
- SpinnerNumberModel(int value, int max, int min, int step) : returns a spinner model whose initial value is set to value, with minimum and maximum value, and a definite step value.
- setValue(Object v) : sets the value of the spinner to the object passed as argument.
- getValue() : returns the current value of the spinner.
- getPreviousValue() : returns the previous value of the spinner.
- getNextValue() : returns the next value of the spinner.
Commonly used methods are :
1. Program to create a simple JSpinner
2. Program to create a JSpinner and add ChangeListener to it ; Program to select your date of birth using JSpinner)
Note : This program will not run in an online compiler please use an Offline IDE
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.