0

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");
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • 2
    What is the problem with your code? Is your `JDateChooser` a third party component? If so which library? – dic19 Sep 25 '13 at 14:34

3 Answers3

1

dateChooser.setEnabled(false);

dateChooser.getCalendarButton().setEnabled(true);

So you can't edit the textfield integrated to the JDateChooser.

Miel Pops
  • 11
  • 1
0

Use this code inside try block:

if(
    ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText().isEmpty()
) {
    JOptionPane.showMessageDialog(this, "Date should be filled");
} else {
    //some code
}
Jeroen
  • 60,696
  • 40
  • 206
  • 339
swe02
  • 3
  • 3
0

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");
}
Gregor Ažbe
  • 353
  • 8
  • 12