How to make a time format in Jspinner?

天涯浪子 提交于 2019-12-24 06:42:02

问题


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.


回答1:


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();
    }
}


来源:https://stackoverflow.com/questions/10477688/how-to-make-a-time-format-in-jspinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!