Java Swing - Date Picker dialog to select a date

This is addressed to the few Java Swing developers, who may still be out there and looking for cool widgets.

How many times did you need a date picker widget? you know, like the one from the GWT for example, and there are many others available.

Unfortunatelly the Java Swing library doesn't have a built-in one. Anyways, I found a good starting point here, http://sourceforge.net/projects/datepicker/ -- which is a very nicely done example, a little incomplete, but still good to go.

Because I wanted this widget to be perfect, I've updated and enhanced and it can do the followings:
  • automatic extract the name of the days and months from the Java locale (not like the original from a properties file).
  • automatic detects and display the first day of the week according with the used locale (not like the original that uses hard-coded only US style).
  • correct the coloring in red of the weekend days (not like original that had only Sundays on red, and Saturdays on gray). 
  • corrected the button images to have all the same size (better header than the original)
  • implemented the "close on away click" feature to easily close the picker dialog when click away.
These are the results of the Java Swing widget:

  

The first image is a read-only text-field and a button, which will open the date-picker dialog, as seen in the second image.

We can fast scroll though months and years, or quickly select from the 2 combos, and for the days just press on the date, which you want to select.

Hope you like it -- the source code is available here.

Cheers!

PS: you can see this widget at work, in my free application Money On Thread.

3 comments:

  1. Do you know the SwingX date picker component?
    https://swingx.dev.java.net

    ReplyDelete
  2. Obviuosly I didn't know about that -- thank you -- I checked it out, indeed that JXDatePciker is very neat!

    Cheers.

    ReplyDelete