use GregorianCalendar and set it to the first date you want
another gc set to the end date
you want to show the date in a particular format, so you'd use SimpleDateFormat()
then it's just
while(gcStart.after(gcEnd) == false)//dates inclusive
{
combo.addItem(sdf.format(gcStart.getTime()));
gcStart.[add a day];
}
//here is an example how to get the date
//I think this might help you!!!
import java.text.DateFormat;
import java.util.Date;
public class DateFormatExample1 {
public static void main(String[] args) {
// Make a new Date object. It will be initialized to the current time.
Date now = new Date();
// See what toString() returns
System.out.println(" 1. " + now.toString());
// Next, try the default DateFormat
System.out.println(" 2. " + DateFormat.getInstance().format(now));
// And the default time and date-time DateFormats
System.out.println(" 3. " + DateFormat.getTimeInstance().format(now));
System.out.println(" 4. " +
DateFormat.getDateTimeInstance().format(now));
// Next, try the short, medium and long variants of the
// default time format
System.out.println(" 5. " +
DateFormat.getTimeInstance(DateFormat.SHORT).format(now));
System.out.println(" 6. " +
DateFormat.getTimeInstance(DateFormat.MEDIUM).format(now));
System.out.println(" 7. " +
DateFormat.getTimeInstance(DateFormat.LONG).format(now));
// For the default date-time format, the length of both the
// date and time elements can be specified. Here are some examples:
System.out.println(" 8. " + DateFormat.getDateTimeInstance(
DateFormat.SHORT, DateFormat.SHORT).format(now));
System.out.println(" 9. " + DateFormat.getDateTimeInstance(
DateFormat.MEDIUM, DateFormat.SHORT).format(now));
System.out.println("10. " + DateFormat.getDateTimeInstance(
DateFormat.LONG, DateFormat.LONG).format(now));
}
}
Here's a quick trial of a custom component. You can add a variety of constructors.
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import static java.util.Calendar.*;
public class DateComboBox extends JComboBox{
static final Locale loc = Locale.US;
SimpleDateFormat dateFmt;
GregorianCalendar startDay;
int daysSpan;
Vector<GregorianCalendar> dvec;
Vector<String> svec;
public DateComboBox(GregorianCalendar start, int span, String fmtString){
GregorianCalendar curDate;
startDay = start;
daysSpan = span; // days; not month, year, hour etc.
dateFmt = new SimpleDateFormat(fmtString, loc);
curDate = startDay;
svec = new Vector<String>();
dvec = new Vector<GregorianCalendar>();
for (int i = 0; i < span; ++i){
dvec.add(curDate);
svec.add(dateFmt.format(curDate.getTime()));
curDate.add(DAY_OF_MONTH, 1);
}
setModel(new DefaultComboBoxModel(svec));
}
public Vector<GregorianCalendar> getDateVector(){
return dvec;
}
public GregorianCalendar[] getDateArray(){
return (GregorianCalendar[])(dvec.toArray());
}
public static void main(String[] args){
DateComboBox dcb = new DateComboBox(
new GregorianCalendar(2007, 0, 1),
61,
"MMM-dd-yyyy");
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(dcb, BorderLayout.NORTH);
frame.setSize(300, 300);
frame.setVisible(true);
}
}