JTable is a Java class that is part of the Swing library. Swing is a graphics library built into Java, allowing you to construct user interfaces that can display on any operating system that supports the Java Runtime Environment. You can create a date-picking element in your Swing application by creating a new date picker object with the range information in its constructor.
- Skill level:
- Moderately Easy
Other People Are Reading
Open your Java source code document and navigate to the JTable object you have created inside of your Swing class.
Create a new TableModel object that holds a DatePickerTable. You must create the DatePickerTable with a range of date values in MMDDYYYY format. The first value is the begin date and the last is the end date. In code, this looks like:
TableModel date Picker = new DatePickerTable("01011999","12302000");
Set the display interval in the date Picker object. By default each day is displayed, but you may set a regular interval. To set a 15-day interval between date options, use this code:
datePicker.interval = 15;
Attach your table model into your JTable:
JTable newtable = new JTable (datePicker);
Your Java application now has a drop-down date selection dialogue.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for