Empty JDateChooser

Unoken Mouny picture Unoken Mouny · Feb 18, 2013 · Viewed 17.6k times · Source

I'm using JDateChooser for a Javaapp (this is the 1st time i use it). I want to catch fault when the JDateChooser is empty with code like this:

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;

But it dont work. Any1 can help me plzz.

Answer

Irshad Khan picture Irshad Khan · Jun 3, 2013
Date date;
date = JDateChooser.getDate();

if (date == null) 
        {
            JOptionPane.showMessageDialog(null, "Choose Date from Right Box.", "Error", JOptionPane.ERROR_MESSAGE);
            JDateChooser.grabFocus();
            return false;
        }