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.
- Java Swing | Translucent and shaped Window in Java
- JRadioButton | Java Swing
- Java Swing | JToolBar
- Java Swing | JTextField
- Java Swing | ToolTip
- Java Swing | MatteBorder
- Java Swing | JMenuBar
- Java Swing | JTextArea
- Java Swing | JTable
- Java Swing | JPopupMenu
- JLabel | Java Swing
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | Look and Feel
- Java Swing | JFileChooser
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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.