Search code examples
javaswingdatejspinnercustom-datetimepicker

Java spinner (JSpinner) want to set a custom date


I had the JSpinner as the given below date format.It takes only the current time as value. But my problem is I want to make it like default value as 12:00 am|11-11-2021 (any values but custom).

From_spinner = new JSpinner(); 
From_spinner.setEnabled(true);
From_spinner.setFont(new Font("Bitstream Charter", Font.PLAIN, 20));                        
From_spinner.setModel(new SpinnerDateModel(new Date(), null, null, 
java.util.Calendar.HOUR_OF_DAY));
JSpinner.DateEditor te1 = new JSpinner.DateEditor(From_spinner, "hh:mm aa|dd-MM-yyyy"); 

Solution

  • https://www.tutorialspoint.com/java/util/calendar_setfield1.htm You can use custom object of calendar and use it as a JSpinner value. Example set year and date as you need in object and use it in you spinner.