DatePicker applet



The DatePicker is a small calendar control that lets users pick dates from a calendar rather than having to type them in. It can be used throughout your user interface for selecting dates. DatePicker also provides a convenient way for your application to determine today's date.

This document describes the following topics:

For general information about DevPack applets, see the following topics:

Using the DatePicker applet

The DatePicker applet can provide the date selection function in your user interface. DatePicker allows users to pick a date from a calendar display, which is far easier and more effective than requiring them to type the date into an edit control. You can also use the DatePicker to get today's date.

Both the selected date and today's date are available either in the form of a Java Date object or as strings of date components such as the day, month, and year. Events are raised whenever either date changes. (See Event table for more information.) The selected date can also be set from the program. The available date properties are:

The DatePicker API consists of properties that can be programmatically set and read by your application. All the API properties belong to the DatePicker class. In many cases, the properties can also be set using PARAM tags within the HTML <APPLET> tag. The properties and PARAM tags are described below.

You can use the DatePicker as a simple date selection control that takes up a minimum of screen space, or you can selectively display various controls to give the user access to additional features. Among DatePicker's additional features are multi-month displays, support for traditional and national calendar systems used throughout the world, and user controls for setting calendar options. These are described below.

The standard one-calendar display, with all controls enabled.

Calendar controls

The DatePicker has a number of controls. Most are hidden by default but can be displayed at the discretion of the application. The controls and their related properties and PARAM tags are shown in the table below.

The view and calendar system selectors in the user interface are disabled by default. When both are disabled, the buttons are not displayed, reducing the screen space required for the calendar.

DatePicker display modes

The DatePicker has three display modes, controlled by the View property or view PARAM tag.

One-month display Three-month display Two-calendar system display

Hiding the calendar

You can also hide the entire calendar. You can use this feature to pop up the calendar only when your interface requires the user to select a date. You can also hide the calendar if you only want to use its today's date feature.

Summary of DatePicker display option properties


Function Display/hide
UI control
Get/set value
Entire calendar AllowUI property --
Banner BannerVisible property
bannerVisible PARAM tag
--
Calendar system CalendarSelectorVisible property
calendarSelectorVisible PARAM tag
Calendar property
calendar PARAM tag
ReferenceCalendar property
referenceCalendar PARAM tag
Display mode ViewSelectorVisible property
viewSelectorVisible PARAM tag
View property
view PARAM tag
First day of week DayMenuVisible property
dayMenuVisible PARAM tag
StartOfWeek property
startOfWeek PARAM tag
Weekend days DayMenuVisible property
dayMenuVisible PARAM tag
Weekend property
weekend PARAM tag
Language no user control UserInterfaceLanguage property
userInterfaceLanguage PARAM tag

DatePicker applet dimensions

You allocate screen space to the DatePicker by setting width and height parameyers in the <APPLET> tag when inserting the DatePicker on your Web page. The width of the calendar display is always 185 pixels. However, the height depends on the display options chosen. The table below shows the required height, in pixels, when various display elements are enabled or disabled.


Display mode No control
No banner
With banner With controls With both
One month 122 154 142 172
Three month 310 347 335 365
Two calendar
system
310 347 335 365

Controlling screen display colors

The display colors of many components of the UI can be controlled by properties or parameters, as shown below.

Color properties Color PARAM tags

Supported calendar systems

The DatePicker allows the user to work and select dates in any one of fifteen calendar systems. The default system is Gregorian -- the standard western calendar. And though the user can select dates in terms of the chosen calendar system, most calendar properties translate dates to their Gregorian equivalents. (The exceptions are the LocalSelectedDateAsString property and LocalTodayDateAsString property. These properties report dates in the current calendar system of the primary calendar.)

The supported calendar systems are:


Note: The calendar calculation algorithms used in the DatePicker applet have been supplied under license from Ed Reingold / Nachum Dershowitz. For further information refer to Calendrical Calculations (Paperback ISBN: 0-521-56474-3, Hardback ISBN: 0-521-56413-1) or visit their Web site at http://emr.cs.uiuc.edu/home/reingold/calendar-book/index.shtml.

Working with dates

The DatePicker applet represents today's date and the selected date using the Java Date object. The Date object is designed to work together with the Java Calendar object to provide date arithmetic and other related functions. Both of these objects are available to your JavaScript application. Hints for using them are given below.

Creating Date and Calendar objects

You can create a Java Date, Calendar, and other objects using the ScriptHelper applet. Here is the procedure:
  1. Embed the ScriptHelper applet in your Web page.
  2. To create a Java Date, call the ScriptHelper.createDate method. You can initialize the date using a string or integer values.
  3. To create a Java Calendar, call the ScriptHelper.createJavaCalendar() method. You can set the date of the Calendar object to the date of a Date object by calling Calendar.setTime(Date). (setTime() sets all fields, including the year, month, and day.)

Changing the date or time of a Date object

A common requirement is to calculate the interval between two Date objects or to change the date or time of an existing Date object. For instance, you may want to increment a date by a constant amount. To do so, use a Calendar object as an intermediary. Here is the general procedure:

The example illustrates this procedure. It accepts a Java date and the number of days by which the date is to be incremented. It calculates the new date, incrementing the month and year as needed. It then creates a new Java date with this value and returns it. You can use the same technique for your own date arithmetic.

IncrementDateByDays Example

///////////////////////
// java.util.Calendar field constants
// use these constants with the java.util.Calendar.get( fieldConstant ) method.
// the java.util.Calendar.set( fieldConstant ) method cannot be used in a Javascript application.

var JCAL_YEAR = 1;
var JCAL_MONTH = 2;
var JCAL_DAY = 5;
var JCAL_AMPM = 9;
var JCAL_HOUR = 10;
var JCAL_24HOUR = 11;
var JCAL_MINUTE = 12;
var JCAL_SECOND = 13;

function IncrementDateByDays(javaDate, noOfDays)
{
} // end incrementDateByDays()

DatePicker example

The following example demonstrates how to embed the DatePicker applet in a Web page and use it to insert dates into another applet.

DatePicker example