设置时间格式的JSpinner

上图:

封装成函数:

public class GetSpinner{

    JSpinner spinner;
    String format = "HH:mm:ss";
    DateFormat timeFormat = new SimpleDateFormat(format);
    public JSpinner getSpinner() {
        spinner = new JSpinner();
        spinner.setFont(SetFont.getFont().deriveFont(16.0F));
        SpinnerModel dateModel=null;
        try {
            dateModel = new SpinnerDateModel(timeFormat.parse("22:22:22"), null, null, Calendar.MINUTE);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        spinner.setModel(dateModel);
        
        //对spinner的时间格式进行设置
        spinner.setEditor(new JSpinner.DateEditor(spinner,format));
        return spinner;
    }
}


代码中的spinner.setFont(SetFont.getFont().deriveFont(16.0F));其中SetlFont为自定义的字体;

可以见http://blog.csdn.net/aigochina/article/details/8085464

需要使用是,直接获得:

JSpinner dateSpinner=new GetSpinner().getSpinner();

你可能感兴趣的:(设置时间格式的JSpinner)