[英]How to pass JTable string date to JDateChooser?
I'm trying to pass the data from the JTable
for which all the types are String
then I want to pass to the JDateChooser
when the user selected the row in the table.我正在尝试从
JTable
传递所有类型都是String
的数据,然后当用户选择表中的行时我想传递给JDateChooser
。 But I tried parsing the date from string to date type but still, I got an error saying illegal value.但是我尝试将日期从字符串解析为日期类型,但仍然出现错误,提示值非法。
Here is the code.这是代码。
private void tableDataMouseClicked(java.awt.event.MouseEvent evt) {
try{
DefaultTableModel model = (DefaultTableModel) tableData.getModel();
int selectedRowIndex = tableData.getSelectedRow(); //get selected row
Fname.setText(model.getValueAt(selectedRowIndex,1).toString());
Lname.setText(model.getValueAt(selectedRowIndex,2).toString());
ageSpin.setValue(model.getValueAt(selectedRowIndex,3).toString());
Date date = new SimpleDateFormat("yyyy-MM-dd").parse((String)model.getValueAt(selectedRowIndex, 4).toString());
dob.setDate(date);
addressField.setText(model.getValueAt(selectedRowIndex,5).toString());
phoneNumField.setText(model.getValueAt(selectedRowIndex,6).toString());
emailField.setText(model.getValueAt(selectedRowIndex,7).toString());
}catch(ParseException e){
e.printStackTrace();
Logger.getLogger(addCitizzen.class.getName()).log(Level.SEVERE, null, e);
}
}
Here is the error I'm getting:这是我得到的错误:
java.lang.IllegalArgumentException: illegal value
The program gives an error when it reaches the Date
part.程序到达
Date
部分时会出错。
The error is arising due to argument passed.错误是由于传递的参数而引起的。 Here is the working one:
这是工作的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.