简体   繁体   中英

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"); 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM