Java – JCalendar for Date Selection

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);
  }
}

 

3. See what you get

 

Done =)

Reference: JCalendar Java Bean, a Java Date Chooser

18 thoughts on “Java – JCalendar for Date Selection”

  1. 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

    Like

      1. 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

        Like

      2. 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. =)

        Like

  2. God Thank you… First Usefull Post… I am Serious… Yes it should appear by default. Are you sure you imported the library correctly?

    Like

  3. I HAVE TRIED YOU DEMO BUT I GOT THE MENTIONED ERRORS BELLOW,MAY HAVE ANY HELP IN ADVANCE.

    C:\java\bin>javac Demo.java
    Demo.java:3: error: package com.toedter.calendar does not exist
    import com.toedter.calendar.JDateChooser;
                               ^
    Demo.java:41: error: cannot find symbol
        JDateChooser dateChooser = new JDateChooser();
        ^
      symbol:   class JDateChooser
      location: class Demo
    Demo.java:41: error: cannot find symbol
        JDateChooser dateChooser = new JDateChooser();
                                       ^
      symbol:   class JDateChooser
      location: class Demo
    3 errors
    
    C:\java\bin>
    

    Like

  4. 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?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.