1

I am working on a java project using SQL and I need to display the current date on a JDateChooser.

Before my client change it with his need I used this in the constuctor

java.sql.Date date = new java.sql.Date(new java.util.Date().getTime());
jdatechooser.setDate(date);

I've also tried

   java.util.Date mydate = new java.util.Date();
   jdatechooser.setDate(date);

But neither of them work. Any help, please?

RubioRic
  • 2,442
  • 4
  • 28
  • 35

2 Answers2

0

JDateChooser from JCalendar 1.4 works fine.

I've just tested this example where this is a JPanel

   JLabel label = new JLabel("Choose date");        
   this.add(label);

   Calendar calendar = new GregorianCalendar(2011, Calendar.JULY, 3);
   calendar.add(Calendar.DAY_OF_MONTH, -7);

   Date date = new Date(calendar.getTimeInMillis());

   JDateChooser jdc = new JDateChooser();
   jdc.setDate(date);

   this.add(jdc);

Choose date

JDateChoose.setDate accepts java.util.Date. You have to convert your obtained time from the DB to it.

BTW: You have a typo on your second excerpt, maybe that's the problem

java.util.Date mydate = new java.util.Date();
jdatechooser.setDate(date);

Should be

java.util.Date mydate = new java.util.Date();
jdatechooser.setDate(mydate);
RubioRic
  • 2,442
  • 4
  • 28
  • 35
0

Date Get_Date = new Date(); // this code to get the current date

jDateChooser1.setDate(Get_Date); // to set the current date to jDateChooser

  • Please post the answer if you have an alternative or value ad to the existing answer. Right now, this solution is covered in existing answer. – Raju May 16 '16 at 23:02