- Trending Categories
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 date spinner in Java?
To create a date spinner, use the SpinnerDateModel class. Within that set the date format −
Date today = new Date(); JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "dd/MM/yy"); spinner2.setEditor(editor);
Above, we have set the Date format to be −
dd/MM/yy
The following is an example to create a date spinner in Java −
Example
package my; import java.awt.GridBagLayout; import java.util.Calendar; import java.util.Date; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { JFrame frame = new JFrame("Spinner Demo"); JPanel panel = new JPanel(); JLabel label = new JLabel("Exam No."); JLabel label2 = new JLabel(" Appeared On"); panel.setLayout(new GridBagLayout()); int min = 0; int max = 10; int step = 1; int i = 5; SpinnerModel value = new SpinnerNumberModel(i, min, max, step); JSpinner spinner = new JSpinner(value); spinner.setBounds(50, 80, 70, 100); Date today = new Date(); JSpinner spinner2 = new JSpinner(new SpinnerDateModel(today, null, null, Calendar.MONTH)); JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner2, "dd/MM/yy"); spinner2.setEditor(editor); panel.add(label); panel.add(spinner); panel.add(label2); panel.add(spinner2); frame.add(panel); frame.setSize(550,300); frame.setVisible(true); } }
Output
- Related Articles
- How to create a List Spinner in Java?
- How to create a Number Spinner in Java?
- How to Create a Spinner in JavaFX?
- How to create date object in Java?
- How to create spinner Programmatically from array in Android?
- Java Program to set a spinner of dates in Java
- How to create Date object from String value in Java?
- How to create a Date object in JavaScript?
- How to parse date sting to date in Java?
- How to create Date Picker in ReactJS?
- How to get Spinner Value in android?
- How to get Spinner value in Kotlin?
- How to Add Spinner Loader in NextJS?
- Create a Date object using the Calendar class in Java
- How to create a table with date column?

Advertisements