Does Swing come with Calendar and time field components?

I would like to have Date and Time fields in my jPanel application so that the user can pick a date and time from a drop down lists. Is there any Swing component out there which I can use rather than having to re-invent the wheel??!
snajalmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:

choose here different variants:
http://www.java2s.com/Code/Java/Swing-Components/SwingDateselectorChooserhighlight.htm
aee links at the bottom
0
for_yanCommented:
this also seemms simple, maybe the same as before:
http://ykyuen.wordpress.com/2011/09/05/java-swing-datepicker-1/
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

for_yanCommented:
How wuould you select time form the dropdown list?
It is common with date, but I don't think such elemnt is common with time - you can have drop down list say by hours, or two dropdowns
- by hours and minutes
0
for_yanCommented:

I downloaded and tried this - works nicely for me:
http://sourceforge.net/projects/flib/files/flib/FLib%201.1.1/
0
for_yanCommented:


Unzip the zip file which you'll download from flib int some folder "Folder"

Copy directory org from  Folder\FLib\JCalendar as a whole to the src folder of your project

Then take the code below
(it is from Folder\FLib\JCalendar\doc\example I removed package line fiorm the top for simplicity)
and import it as file Example1.java
into your project.

Compile and execute Example1.java  

Seems to be a good date-time picker
see pictures:
http://flib.sourceforge.net/JCalendar/doc/screenshots.html


//**********************************************************************
// Package
//**********************************************************************



//**********************************************************************
// Import list
//**********************************************************************

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.Calendar;
import java.util.Locale;
import org.freixas.jcalendar.*;

/**
 * This example shows various instances of the JCalendar class.
 * <hr>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Artistic License. You should have
 * received a copy of the Artistic License along with this program. If
 * not, a copy is available at
 * <a href="http://opensource.org/licenses/artistic-license.php">
 * opensource.org</a>.
 *
 * @author Antonio Freixas
 */

// Copyright © 2004 Antonio Freixas
// All Rights Reserved.

public class Example1
    extends JFrame
{

//**********************************************************************
// main
//**********************************************************************

public static void
main(
    String[] args)
{
    new Example1();
}

//**********************************************************************
// Constructors
//**********************************************************************

/**
 * Create various instances of a JCalendar.
 */

public
Example1()
{
    // Set up the frame

    setTitle("Example1");
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.setLayout(new GridLayout(2, 2, 5, 5));

    // Create a border for all calendars

    Border etchedBorder =
	BorderFactory.createEtchedBorder();
    Border emptyBorder =
	BorderFactory.createEmptyBorder(10, 10, 10, 10);
    Border compoundBorder =
	BorderFactory.createCompoundBorder(etchedBorder, emptyBorder);

    // Create a date listener to be used for all calendars

    MyDateListener listener = new MyDateListener();

    // Display date and time using the default calendar and locale.
    // Display today's date at the bottom.

    JCalendar calendar1 =
	new JCalendar(
	    JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
	    true);
    calendar1.addDateListener(listener);
    calendar1.setBorder(compoundBorder);

    // Set fonts rather than using defaults

    calendar1.setTitleFont(new Font("Serif", Font.BOLD|Font.ITALIC, 24));
    calendar1.setDayOfWeekFont(new Font("SansSerif", Font.ITALIC, 12));
    calendar1.setDayFont(new Font("SansSerif", Font.BOLD, 16));
    calendar1.setTimeFont(new Font("DialogInput", Font.PLAIN, 10));
    calendar1.setTodayFont(new Font("Dialog", Font.PLAIN, 14));

    // Display date only

    JCalendar calendar2 = new JCalendar(JCalendar.DISPLAY_DATE, false);
    calendar2.addDateListener(listener);
    calendar2.setBorder(compoundBorder);

    // Display time only and set the time pattern to use as a duration
    // from 00:00 to 23:59

    JCalendar calendar3 =
	new JCalendar(
	    Calendar.getInstance(),
	    Locale.getDefault(),
	    JCalendar.DISPLAY_TIME,
	    false,
	    "HH:mm");
    calendar3.addDateListener(listener);
    calendar3.setBorder(compoundBorder);

    // Display a French calendar

    JCalendar calendar4 =
	new JCalendar(
	    Calendar.getInstance(Locale.FRENCH),
	    Locale.FRENCH,
	    JCalendar.DISPLAY_DATE | JCalendar.DISPLAY_TIME,
	    false);
    calendar4.addDateListener(listener);
    calendar4.setBorder(compoundBorder);

    // Add all the calendars to the content pane

    JPanel panel1 = new JPanel(new FlowLayout());
    panel1.add(calendar1);
    contentPane.add(panel1);

    JPanel panel2 = new JPanel(new FlowLayout());
    panel2.add(calendar2);
    contentPane.add(panel2);

    JPanel panel3 = new JPanel(new FlowLayout());
    panel3.add(calendar3);
    contentPane.add(panel3);

    JPanel panel4 = new JPanel(new FlowLayout());
    panel4.add(calendar4);
    contentPane.add(panel4);

    // Make the window visible

    pack();
    setVisible(true);
}

//**********************************************************************
// Inner Classes
//**********************************************************************

private class MyDateListener
      implements DateListener
{

public void
dateChanged(
    DateEvent e)
{
    Calendar c = e.getSelectedDate();
    if (c != null) {
	System.out.println(c.getTime());
    }
    else {
	System.out.println("No time selected.");
    }
}

}

//**********************************************************************
// End Inner Classes
//**********************************************************************

}

Open in new window





0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
This is the classic date picker

http://www.toedter.com/en/jcalendar/
0
snajalmAuthor Commented:
The one that I ended up using was JXDatePicker from the Swingx project which was pretty cool and made my purpose!  But thanks guys for your kind and valuable responses!
0
Vanavah EdwardsCommented:
There are so many suggestions here and they all seem to be solutions.  My interent link seems to went down therefore I missed all these intelligent suggestions.  I am only now starting to receive my emails again so I would need a little time to review the solutions.
0
for_yanCommented:
Sure, take as much time as you want :)
I'd first try the accepted solution as I looked at it more attentively - it seemed reasonable to me .
0
for_yanCommented:
rather switch to your question - otherwise we are disturbing the author of this old trail with emails, ect.
0
Vanavah EdwardsCommented:
THIS IS FOR "for_yan:"
Your date solution from flib and your source code works well and is a solution.  I set this up as a separate class and pass parameters.  However, I still have to return the date to my class in the format I require "mm/dd/yy".  I cant seem to get the actual date in alone my format from the c.getTime() or any other date methods.  Can you help me and that would be the end.  Thanks.
0
Vanavah EdwardsCommented:
THIS IS FOR expert "for_yan:"
I have not heard from you concerning my last comment.  Are you still there?  Can you please give me some feedback please concerning solution 10/23/11 09:30 PM, ID: 37015932?  See my last comment.
0
for_yanCommented:
Look, I posted in your ltrail - don't post in this old question

http://www.experts-exchange.com/Programming/Languages/Java/Q_27476343.html
0
Vanavah EdwardsCommented:
THIS IS FOR expert "for_yan:"
Solution ID 10/23/11 09:30 PM, ID: 37015932 says the solution was accepted but no point was awarded.  However, I just accepted the comment but I haven't awarded any point yet.  How can this be.  I have not heard from you concerning my last comment.  Are you still there?  Can you please give me some feedback please concerning solution 10/23/11 09:30 PM, ID: 37015932?  See my last comment.
0
for_yanCommented:
DOn't understand anything - are you reading my posts - look above your post - and please, don't post in this old trail - it causes excessive email traffic to those people who may not be interested in it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.