theotherbell.com
Google
Search WWW
Search opensource.theotherbell.com


Home
The Mac Zone
How-To's
Solutions
Commentaries
HyperLinux
Credits
AUP
Valid HTML 4.01!

Print (Printer-friendly display)

DatePicker and DateEdit are two Swing components that let you easily add calendar functionality to your Java application. Both components extend JPanel so they can be incorporated into dialogs, frames and other Swing components that support JPanel components.

The following sample code illustrates how the DateEdit component is used in a dialog:

    JDialog dlg = new JDialog(new Frame(), true);
    DateField df = new DateField();
    dlg.getContentPane().add(df);
    dlg.pack();
    dlg.show();
    System.out.println(df.getDate().toString());

When the dialog is initially displayed, the user sees the DateEdit component: When the user clicks on the button to the right of the text box, the DatePicker component becomes visible; the user clicks on the back and forward buttons to change the current month: When the user selects a date by clicking on a specific day in the calendar or clicking the Today button, the DatePicker component disappears and the selected date appears in the text box; in this example, the user clicked on 31: If the user clicks on the button again, the calendar is initialized to the date shown in the text box.
Figure 1 Figure 2 Figure 3 Figure 4

DatePicker can also be used independent of DateEdit by changing its default selection behavior:

    JDialog dlg = new JDialog(new Frame(), true);
    DatePicker dp = new DatePicker();
    dp.setHideOnSelect(false);
    dlg.getContentPane().add(dp);
    dlg.pack();
    dlg.show();
    System.out.println(dp.getDate().toString());

SourceForge.net Logo DatePicker and DateEdit are part of the Java Date Picker project registered at SourceForge.


Powered by Apache Powered by MandrakeHome | Feedback | Report a broken linkJoin the fight
surd-subversive
surd-subversive
surd-subversive
surd-subversive