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
- Java Swing | ScrollPaneLayout Class
- Java Swing | JPanel with examples
- Java Swing | Internal Frame with examples
- Java Swing | JMenuBar
- Java Swing | JFileChooser
- Java Swing | Look and Feel
- Java Swing | JTextField
- Java Swing | JProgressBar
- Java Swing | JPasswordField
- Java Swing | JPopupMenu
- Java Swing | JTextArea
- JLabel | Java Swing
- Java Swing | JToolBar
- JRadioButton | Java Swing
- Java Swing | ToolTip
- Java Swing | JSlider
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
- Java Swing | Simple Calculator
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 and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
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.