How to list the jComboBox values

advertisements

I m using jComboBox to display the date,month,year and i add the first item in jComboBox as DD,MM,YY(i set the first item as "DD,YY" in model properties of jComboBox).To display the date and year value i used for loop.The code follows..

    //for date
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
    for(int k=1;k<=31;k++)
    {

        jComboBox1.addItem(k);
    }
} 

    //for year
    private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {
    for(int n=1980;n<=2012;n++)
    {

        jComboBox3.addItem(n);
    }
}

So my problem is when i select the DD and YY jComboBox it didn't display the values dynamically.For example when i click the DD jComboBox in the list it shows another item as DD and then if i select only means it display the all values for DD and YY. why?? and how display it dynamically.


your code initialize the JComboBox each time the user click on it , this is wrong

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {                                           

////////////here you put the action like getSelectedItem() which return the item 

}