0

Want to ask how can i compare a textfield with a JDateChooser?

if ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText() < txtdate) { 
    JOptionPane.showMessageDialog(null, "Cant choose a date that is more previous >than the present date!"); 
} else { 
    JOptionPane.showMessageDialog(null, "Book Successfully Borrowed!");
}
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
  • Your code doesn't make sense, you have a `catch` without a `try` block. You shouldn't be comparing text in this way, instead, get the `Date` value the `JDateChooser` and convert the text value from the text field to a `Date` value and use the `Date` objects capabilities to compare them – MadProgrammer Mar 23 '14 at 05:25
  • i just included the catch because the system doesnt allow me to post with a short code >if ((JTextField)jDateChooser1.getDateEditor().getUiComponent()).getText() < txtdate) { JOptionPane.showMessageDialog(null, "Cant choose a date that is more previous >than the present date!"); } else { JOptionPane.showMessageDialog(null, "Book Successfully Borrowed!"); – user3449761 Mar 23 '14 at 05:29
  • If your target is to check if the date is not previous to today, use the getSelectedDate() function and compare it with the current date. – ray Mar 23 '14 at 05:43

0 Answers0