1

How to make a time format like this hourhour:minuteminute:secondsecond,milisecondmilisecondmilisecond

using only one Jspinner when I make this spinner using visual GUI of NET beans.

realprogram
  • 38
  • 2
  • 6

1 Answers1

5

You need to use both, SpinnerDateModel and JSpinner.DateEditor with the correct date format pattern:

public class JSpinnerDateFormat extends JFrame {
    public JSpinnerDateFormat() {
        super("JSpinner Date Format");
        JSpinner spinner = new JSpinner();
        spinner.setModel(new SpinnerDateModel());
        spinner.setEditor(new JSpinner.DateEditor(spinner, "HH:mm:ss.SSS"));
        add(spinner);
        pack();
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);
    }

    public static void main(String[] args) {
        new JSpinnerDateFormat();
    }
}
Moritz Petersen
  • 12,902
  • 3
  • 38
  • 45
  • I don't want the jspinner take the current time of my computer. I want when I give a time as a input, the jspineer take it And as I wish I can increase or decrease. how can I do this? – realprogram May 07 '12 at 11:05
  • Please read the docs! For example, you can set the value with `spinner.setValue(myDate);`. Increase and decrease are built in to JSpinner, just give it a try! – Moritz Petersen May 07 '12 at 11:58