MSeries.Calendar.MDateSelector


back


www.jars.com

The MDateSelector is a 100% Java Swing Popup Dialog that provides a Calendar to allow dates to be 'picked off' and returned to the date entry field on the Frame. Using this sort of control allows only valid dates to be entered and can remove the need for some validation. It was written to demostrate several techniques. The main Calendar is a custom component (MDateSelectorPanel) which may be used in any Swing application, it is a JavaBean and can be demonstrated in the BeanBox. This component and the heading showing the dates both have pluggable look and feels following the Swing patterns with self installed ones for Metal, Motif and Windows look and feels. A custom look and feel can easily be provided.


More Screen Shots...

Features

  • Programmable upper and lower date limits with defaults
  • Programmable foreground and background colours, even a background image can be set.
  • Programmable alternative colours for specific days of the week (e.g. weekends as shown) and for specific dates.
  • Fully internationalised, the programmer provides a ResourceBundle
  • Programmable date format on display
  • Complete mouseless operation using keyboard
  • First day of week can be any day
  • Pluggable look and feel for all custom components
  • 100% Java (JDK1.4.x & other versions)

Usage

The following code snippet shows one of my test classes that activates the MDateSelector on a right mouse click in the date entry field. This can be run by typing

    java -classpath .\MDateSelector.jar mseries.ui.MDateEntryFieldDemo


in the directory containing the jar file.

    public void mouseReleased(MouseEvent e)
    {
        if (e.isPopupTrigger())
        {
            try
            {
                date = df.parse(getText());
            }
            catch(ParseException pe)
            {
                date = null;
            }

            MDateSelector popup;
            popup = new MDateSelector(minDate, maxDate);
            popup.setDateFormatter(DateFormat.getDateInstance
					(DateFormat.LONG));
            popup.setTextLocalizer(rb);
            popup.setFirstDay(Calendar.MONDAY);
            popup.setForeground(Calendar.SATURDAY, Color.blue);
            popup.setForeground(Calendar.SUNDAY, Color.blue);

            Point p=e.getPoint();
            p.x+=getBounds(null).x;
            p.y+=getBounds(null).y;
            popup.show(getParent(), p, date);

            date = popup.getValue(); 
            setText(date==null ? "" : shortFormatter.format(date));
            popup=null;
       }
   } 


Note that the order of the method calls, if used setTextLocalizer should be called before any other method.

 

Downloads

The jar, source code and javadocs may be downloaded from the downloads page