JTable日期值到jspinner

JTable日期值到jspinner

问题描述:

我已经显示了一个格式为MM/dd/yyyy的日期值,并且我希望它在jtablemouseclickedevent上显示给jsinner.我该怎么办?我用此代码尝试过,但出现错误:

i have displayed a date value formatted MM/dd/yyyy and i want it to display to jsinner on jtablemouseclickedevent. how would i do that? i tried it with this code but i get an error:

我的jtable有5列

my jtable has 5 columns

ID = int type
Username = String type
Password = String type
Website = String type
Date Encoded = date/time type (MM/dd/yyyy)

这是我的代码:

jLabel5.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString());
jTextField4.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString());
jTextField5.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString());
jTextField6.setText(jTable1.getValueAt(jTable1.getSelectedRow(), 3).toString());
**jSpinner1.setValue(jTable1.getValueAt(jTable1.getSelectedRow(), 4));**

任何帮助将不胜感激:) :):)

any help would be greatly appreciated :) :) :)

您使用 SpinnerDateModel 并传递一个字符串作为值( jTable1.getValueAt(jTable1.getSelectedRow(),4).toString())而不是日期.在将字符串传递给微调框之前,将其转换为日期(或者也许您已经有一个日期).

You use SpinnerDateModel and pass a String as the value (jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString()) instead of a date. Convert the string to a date (or maybe you even got a date already) before passing it to the spinner.