- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a JSpinner in Java with values as numbers?
Use SpinnerNumberModel to create a spinner with value as numbers −
SpinnerModel value = new SpinnerNumberModel(10, 0, 20, 1);
Now set the values −
JSpinner spinner = new JSpinner(value);
The following is an example to create a JSpinner with values as numbers −
Example
package my; import java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Spinner Demo"); SpinnerModel value = new SpinnerNumberModel(10, 0, 20, 1); JSpinner spinner = new JSpinner(value); spinner.setBounds(50, 80, 70, 100); frame.add(spinner); frame.setSize(550,300); frame.setLayout(null); frame.setVisible(true); } }
This will produce the following output −
Advertisements