Hey guys. In my application I have a JComboBox called yearsCombo which has different years as elements. I've attached an actionListener to the combo. When I change the combobox, in the actionPerformed it is not recognizing that e.getsource == yearsCombo. Also, when I get the selectedItem of the combo, it always returns the first item, even when I select another item. Some of the relevent code is below. Any ideas as to why the actionEvent is not equals to the combo and why the get selecteditem is not working??
Here are the elements of the combo.
[All, 2006, 2005, 2004, 1999, 1998, 1990, 1984, 1983, 1976]
...
public void updateCombos(){
try{
Vector years = jBridge.vectorSelect("select distinct year " +
"from movie.movie " +
"order by year desc");
yearCombo = new JComboBox(years);
yearCombo.addActionListener(this);
...
public void actionPerformed(ActionEvent e) {
String year = (String)yearCombo.getSelectedItem();
int year1 = yearCombo.getSelectedIndex();
log.warn("*********year combo clicked: " + year + " " + year1);
...
else if(e.getSource() == yearCombo){
log.warn("YEARS CLICKED!");
}
...
}
output
[*WARN*] MovieOrganizer.-1: enter action performed: javax.swing.JComboBox[,267,5,56x25,layout=javax.swing.plaf.metal.Metal
ComboBoxUI$MetalComboBoxLayoutManager,alignmentX=0.0,alignmentY=0.0,border=,flags=16777544,maximumSize=,minimumSize=,prefe
rredSize=,isEditable=false,lightWeightPopupEnabled=true,maximumRowCount=8,selectedItemReminder=1998]
[*WARN*] MovieOrganizer.-1: *********year combo clicked: All 0