Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with DateChooser from JCalendar  RSS feed

 
raghav singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

1.How do i obtain and store the date chosen by the user from DateChooser as it is clearly not simple as a JTextField?
2.How do i test for null value for DateChooser.... this is for validation?

For your information i already search on google. Not finding anything related to my two problems.

Thanks in Advance
 
K. Tsang
Bartender
Posts: 3624
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JCalendar is clearly not part of Java Swing API.

What does the JCalendar API say? I believe it will be a java.util.Date
 
Campbell Ritchie
Sheriff
Posts: 53734
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which date chooser? Do you mean Toedter's? That is really easy to use. I think it does return a java.util.Date. You would only get null from it if you close the window without pushing the OK button (or similar).

It returns an object of some sort, so you can simply check
if (date != null)
Or you can put it in a loop
while ((date = JCalendar.showSomeDialogOrOther()) == null) ...
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're on Java 8 and want something that uses the new Date/Time API, you can try my Local Date Combo. It doesn't allow setting a null value though,.
 
raghav singh
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok .Thank you for your helps guys . I have found the solution to my two problems. Here they are in case someone get similar problem in the future:

1.To get date for dateChoooser use this : new java.sql.Date(dateChooser.getDate().getTime()) in my case i needed the time in sql format because i am connected to a sql database
2.To Test For Null Value use this: dateChooser.getDate() == null

Actually what help me was i went to read the dataChooser class(http://grepcode.com/file/repo1.maven.org/maven2/com.luuuis/jcalendar-tz/1.3.3-3/com/toedter/calendar/JDateChooser.java#JDateChooser.%3Cinit%3E%28java.util.Date%2Cjava.lang.String%29). Everything became clear after that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!