• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with DateChooser from JCalendar

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) ...
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic