简体   繁体   English

如何在jspinner中设置预定义的时间

[英]How to set predefined time in jspinner

I have some pre defined time in mysql database in varchar format for example - 16:45, 00:30, 09:15, 20:50 and 10 more. 我在varchar格式的mysql数据库中有一些预先定义的时间,例如 - 16:45,00:30,09:15,20:50和10。

I want to display any one of these time in jspinner I am trying but getting error this my jspinner setup where I am displaying the time this is inside constructor- 我想在jspinner中显示这些时间中的任何一个我正在尝试但是得到错误这是我的jspinner设置我在哪里显示时间这是在构造函数内部 -

Date date = new Date();
SpinnerDateModel sm = new SpinnerDateModel(date, null, null, Calendar.HOUR_OF_DAY);
arr_time.setModel(sm);
JSpinner.DateEditor ar = new JSpinner.DateEditor(arr_time, "HH:mm");
arr_time.setEditor(ar);

and this my modify button code where I fetching the time as string from database trying to show them in jspinner 这是我的修改按钮代码,我从数据库中获取时间作为字符串,试图在jspinner中显示它们

try {
    if (evt.getActionCommand().equals("Modify")) {
        String flno=JOptionPane.showInputDialog(this, "Enter Flight Number");
        String sql="SELECT * FROM flights WHERE flightno='"+flno+"'";
        smt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
        rs = smt.executeQuery(sql);
        while (rs.next()) {
            jTextField1.setText(rs.getString(1));
            arr_time.setValue(rs.getString(2));
            jTextField4.setText(rs.getString(4));
            jTextField5.setText(rs.getString(5));
        }
    } else if(evt.getActionCommand().equals("Update")) {
    }

run: illegal value 运行:非法值

Error is coming in netbeans 7.1 netbeans 7.1中出现了错误

Although not obvious, the error is telling you the type used to set the JSpinner and the String read in from the database are incompatible. 虽然不是很明显,但错误告诉您用于设置JSpinner的类型和从数据库读入的String是不兼容的。 SpinnerDateModel uses a Date as the underlying object type SpinnerDateModel使用Date作为基础对象类型

Try 尝试

SimpleDateFormat format = new SimpleDateFormat("HH:mm");
arr_time.setValue(format.parseObject(rs.getString(2))); // e.g. input 16:45

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM