Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
// Option 1 : set range
jSpinner2.setModel(new SpinnerDateModel(new java.util.Date(1388498400000L), new java.util.Date(1388484000000L), new java.util.Date(1388505600000L), java.util.Calendar.MINUTE));
// Option 2 : set HH:mm format
jSpinner2.setModel(new SpinnerDateModel(new java.util.Date(1388498400000L), null, null, java.util.Calendar.MINUTE));
JSpinner.DateEditor de = new JSpinner.DateEditor(jSpinner2, "HH:mm");
de.getTextField().setEditable( false );
jSpinner2.setEditor(de);
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new HourSpinner2().setVisible(true);
What I find out is that I can do only one of the 2 at a time. Either set a range or set a format. Doing both would simply freeze the component for user edit.
How to make this work for both range and format?
–
The issue with your code is that actually the formatter throws away the
date
fields and keeps only the
time
part of the current value. But then the value no longer lies between
min
and
max
and this is not changeable.
As a simple workaround you may specify the
min
and
max
values as in the following code:
Calendar cal1 = GregorianCalendar.getInstance();
cal1.clear();
cal1.set(1970, Calendar.JANUARY, 1, 0, 0);
Date min = cal1.getTime();
Calendar cal2 = GregorianCalendar.getInstance();
cal2.clear();
cal2.set(1970, Calendar.JANUARY, 1, 2, 0);
Date max = cal2.getTime();
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.