问题
I have a jFrame in my java application which inserts the selected date into the database. I want to validate if field is empty.
The code is like this:
if(!this.jtxtDate.getSelectedItem.toString().isEmpty()) {
idc.setDate(this.jtxtDate.getDate);
} else {
JOptionPane.showMessageDialog(rootPane, "pls choose date");
}
回答1:
Use this code inside try block:
if(
((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText().isEmpty()
) {
JOptionPane.showMessageDialog(this, "Date should be filled");
} else {
//some code
}
回答2:
You could just check if you can get date from jDateChooser.
if(this.jtxtDate.getDate() != null) {
idc.setDate(this.jtxtDate.getDate);
} else {
JOptionPane.showMessageDialog(rootPane, "pls choose date");
}
回答3:
dateChooser.setEnabled(false);
dateChooser.getCalendarButton().setEnabled(true);
So you can't edit the textfield integrated to the JDateChooser.
来源:https://stackoverflow.com/questions/19007738/validating-a-jdatechooser