4

I've discover this JDateChooser from searching how to use Item Combobox at Java Swing. Do you know how to install this?

Here is the link JDateChooser

I can't find any instructions on how to install it..

Can you share some instructions on how to install it... thanks in advance v(^_^)v

Kai
  • 38,985
  • 14
  • 88
  • 103
iamanapprentice
  • 411
  • 5
  • 19
  • 37

2 Answers2

13

It's very simple.

Download the Toedter jcalendar-1.4.jar (also maven repository will locate it) If you are using Netbeans you can create an new bean and add the Toedter beans to your Palette Manager:

enter image description here

This gives you the capability to drag and drop these anywhere you like:

enter image description here

If you drag and drop the bean somewhere, the code that is generated looks like here:

jDateChooser1 = new com.toedter.calendar.JDateChooser();
jDateChooser1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jDateChooser1.setDateFormatString("dd/MM/yyyy");

You can then use the beans like this:

 java.sql.Date di = rs.getDate("edate");
 jDateChooser1.setDate(di);

or

java.util.Date jud =  jDateChooser1.getDate();
long t = jud.getTime();
java.sql.Date sqd = new java.sql.Date(t);
rs.updateDate("edate", sqd);

or like this if you want to format the Date:

java.util.Date jud =  jDateChooser1.getDate();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MMMM dd, yyyy");
jLabel1.setText(sdf.format(jud));
Costis Aivalis
  • 13,680
  • 3
  • 46
  • 47
  • needs to download Netbeans first, but nice answer. – oliholz Jun 09 '11 at 11:06
  • yeah, i think that for Swing Netbeans is "The Tool"... :-) – Costis Aivalis Jun 09 '11 at 11:09
  • Hi again Costis Aivalis... I have a little problem again.. jDateChooser prints something like this: Thu Jun 16 16:13:03 CST 2011 but what I only need is the Date like something like: June 16, 2011. How should capture the date with MMM dd, YYYY format? thanks again.. :) o by the way... im using this jDateChooser1.getDate() to capture the input thanks again ^_^ – iamanapprentice Jun 10 '11 at 08:16
  • You must use SimpleDateFormat with TimeZone and Date in order to generate the display Strings the way you need. I have just updated the answer to include this for U... – Costis Aivalis Jun 10 '11 at 09:00
  • The links are not working, here is the updated link for the jcalendar-1.4.jar download: http://www.java2s.com/Code/Jar/j/Downloadjcalendar14jar.htm – Sanlyn Nov 05 '22 at 13:09
  • Thank you Sanlyn. The first link (https://toedter.com/software/) is OK. Seems that jarfinder retired. So i updated the second link to maven repository, which always works. – Costis Aivalis Nov 05 '22 at 16:33
4

Add the sources to yours and use the classes like in JCalendarDemo.java

oliholz
  • 7,447
  • 2
  • 43
  • 82