如何将JSpinner的值设置为特定日期 [英] How to set value of JSpinner to a certain date

查看:147
本文介绍了如何将JSpinner的值设置为特定日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 JSpinner 我添加到 JPanel 我想将时间设置为: GregorianCalendar日历

I have a JSpinner which I add to the JPanel I would like to set its time to the :GregorianCalendar calendar

JSpinner spinner = new JSpinner();
spinner.setModel(model);
pom.add(new JLabel("Date", JLabel.RIGHT));
pom.add(spinner);

如何实现这一点,因为我得到IllegalValue例外。

How to achieve this as I get IllegalValue exceptions.

推荐答案

应该这样做:

        SpinnerDateModel model = new SpinnerDateModel();
        model.setCalendarField(Calendar.DAY_OF_YEAR);

        JSpinner spinner = new JSpinner();
        spinner.setModel(model);

        SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
        java.sql.Time time = new java.sql.Time(osoba.getDataZatrudnienia().getTime().getTime());
        spinner.setValue(time);

这篇关于如何将JSpinner的值设置为特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆