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. Features
UsageThe 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
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;
}
}
|
||
DownloadsThe jar, source code and javadocs may be downloaded from the downloads page |