Previously i have created two posts about a simple Swing Date Picker.
Here comes a better solution – JCalendar.
JCalendar is Java Bean which provides a complete feature of a Date Picker in Java. For more information, please visit JCalendar Java Bean, a Java Date Chooser
The following only shows the basic usage of JCalendar. Hope you could explore its full features base on it.
1. Download the JCalendar.jar @ here
2. Create the following class and run it
Demo.java
import java.awt.EventQueue; import javax.swing.JFrame; import com.toedter.calendar.JDateChooser; public class Demo { private JFrame frame; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Demo window = new Demo(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the application. */ public Demo() { initialize(); } /** * Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 450, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); JDateChooser dateChooser = new JDateChooser(); dateChooser.setBounds(20, 20, 200, 20); frame.getContentPane().add(dateChooser); } }
Done =)
Reference: JCalendar Java Bean, a Java Date Chooser
I try it but it does not work
there are 4 error :cannot find symbol JDateChooser
I exstrack the jcalendar1.4.zip to C:\Java\src\com\tuedter\calendar\JDateChooser
so the lib folder is in JDateChooser folder,
there are 4 executable jar file in lin folder
I place Demo.Java in c:\java \src folder
my javac command is :
javac -d build src Demo.java
what i did wrong ?
thank you
han
LikeLike
can you post the error?
LikeLike
hello
now it work,but
1.lastyear button often jump from 2011 to 2009 ,not stabil,sometime decrease 1 year sometime decrease 2 year.each i pressed it.
2.I call it from command promt,
after i close it
the command promt still blinking,cannot be used for other need
those 2 problem i found hope you can fix it.
If it under gnu licence I interested to use it,because it is quite small in size
Now I use the flip from forge.net
thank you
hanafi tanudjaya
LikeLike
I didn’t have those problem on my eclipse project. i have sent the project to ur email. See if it works for you.
Or you can post the problem to the JCalendar team. =)
LikeLike
Hey ykyuen,
How can I make the date picker with the small “calendar icon” like in your picture???
Many thanks.
LikeLike
as i remember that small icon should appear by default. is your JDateChooser working normally?
LikeLike
God Thank you… First Usefull Post… I am Serious… Yes it should appear by default. Are you sure you imported the library correctly?
LikeLike
You are welcome. =D
LikeLike
I HAVE TRIED YOU DEMO BUT I GOT THE MENTIONED ERRORS BELLOW,MAY HAVE ANY HELP IN ADVANCE.
LikeLike
i think you didn’t include the calendar lib in your project.
LikeLike
Could you please let me know how can jcalander shown in jtextfield after clicking on it.
LikeLike
Why don’t u just use the JDateChooser as shown in the example above?
LikeLike
My question is rather than showing or adding to frame how can we add jcalendar to jtextfield
LikeLike
The following post may help.
http://www2.sys-con.com/itsg/virtualcd/java/archives/0403/duguay/index.html
LikeLike
thank you
it really helped me
but how do i save the date to mysql database
LikeLike
You can refer to the following post
Java JDBC Insert Example: How to insert data into a SQL table | alvinalexander.com
LikeLike
It’s asking me to resolve my JDateChooser object to a Component in order to get rid of the error i have on the “add” method. The add method is not available for the JDateChooser arguement?
LikeLike