I am try to populate a JComboBox with the days of a particular month and year. I researched the problem and came up with this:
public void actionPerformed(ActionEvent e)
{
//code to respond to the buttons goes here
if ( e.getSource() == cmbMonth || e.getSource() == cmbYear ) {
cmbDay.removeAllItems();
int year = Integer.parseInt(cmbYear.getSelectedItem().toString());
int month = cmbMonth.getSelectedIndex() + 1;
Calendar currMonYear = Calendar.getInstance();
currMonYear.set(Calendar.YEAR, year);
currMonYear.set(Calendar.MONTH, month);
int daysInMon = currMonYear.getActualMaximum(Calendar.DAY_OF_MONTH);
for ( int i = 1; i <= daysInMon; ++i )
cmbDay.addItem(i);
int x = 0;
}
}//end actionPerformed()
Though I am getting incorrect values. Any suggestions?