我正在使用JDateChooser作为Javaapp应用程序(这是我第一次使用它)。我想用下面这样的代码在JDateChooser为空的时候捕获错误:
if(dcs1.getDate().toString().isEmpty()){
lblOk.setText("Empty");
}else{
Date d = dcs1.getDate();
DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
String t = df.format(d);
lblOk.setText(t);
}
JLabel lblOk;
JDateChooser dcs1;但是它不起作用。Any1可以帮我解决问题。
发布于 2013-06-03 12:46:48
Date date;
date = JDateChooser.getDate();
if (date == null)
{
JOptionPane.showMessageDialog(null, "Choose Date from Right Box.", "Error", JOptionPane.ERROR_MESSAGE);
JDateChooser.grabFocus();
return false;
}发布于 2014-09-24 03:26:33
String s = ((JTextField)dateChooser.getDateEditor().getUiComponent()).getText();
if (s.equals("") {
JOptionPane.showMessageDialog(null, "Please type birthday", "Warning!", JOptionPane.ERROR_MESSAGE);
}发布于 2013-12-09 16:20:45
if (jDateChooserBirthDate.getDate() == null) {
JOptionPane.showMessageDialog(null, "Please type birthday", "Warning!", JOptionPane.ERROR_MESSAGE);
}https://stackoverflow.com/questions/14930225
复制相似问题