我正在将 JDateChooser 用于 Java 应用程序(这是我第一次使用它)。我想在 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可以帮助我,请。
最佳答案
Date date;
date = JDateChooser.getDate();
if (date == null)
{
JOptionPane.showMessageDialog(null, "Choose Date from Right Box.", "Error", JOptionPane.ERROR_MESSAGE);
JDateChooser.grabFocus();
return false;
}
关于java - 空 JDateChooser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14930225/