Setting JSpinner for countdown timer

392 views Asked by At

I want to use a JSpinner to select a time for a countdown timer where the user selects the HR,MIN,SEC where any of these values can be 00. I was using the SpinnerDateModel but the HR cannot be set to 00

1

There are 1 answers

0
Boann On

The default format of date display by the JSpinner is locale-dependent, but you can customize the date formatting by explicitly setting a JSpinner.DateEditor instance with your desired format as the spinner's editor component:

JSpinner spinner = new JSpinner(new SpinnerDateModel());
spinner.setEditor(new JSpinner.DateEditor(spinner, "HH:mm:ss"));

The HH there will ensure the hour is displayed with leading zeros.