如何将JSpinner的值设置为特定日期
我有一个JSpinner
,我添加到JPanel
我想将它的时间设置为: GregorianCalendar calendar
JSpinner spinner = new JSpinner(); spinner.setModel(model); pom.add(new JLabel("Date", JLabel.RIGHT)); pom.add(spinner);
如何实现这一点,因为我得到IllegalValueexception。
应该做的事情:
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);