Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] JComboBox and ActionListener


  • From: Christian.Ribeaud@xxxxxxxxxxxx (Christian Ribeaud)
  • Subject: [Advanced-java] JComboBox and ActionListener
  • Date: Wed, 23 Jan 2002 14:15:34 +0100

Hi,

I have been having problems with the following code:
...
public static class MyJComboBox extends JComboBox {
  public MyJComboBox(String[] s) {
    super(s);
  }

  public void setAllItems(String[] s) {
    removeAllItems();
    for (int i = 0; i < s.length; i++) {
      addItem(s[i]);
    }
  }
}

comboBoxField = new MyJComboBox(new String[]{});
comboBoxField.addActionListener(new ComboBoxAction());

private class ComboBoxAction extends AbstractAction{
  public void actionPerformed(ActionEvent ae){
    fireComboBoxEvent();
  }
}

protected void fireComboBoxEvent(){
  MyEvent me = new MyEvent(MyJTextField1.getText(),
    MyJTextField2.getText(),
    (String)comboBoxField.getSelectedItem(),
    this,
    MyEvent.COMBOBOX,
    attemptCount);
  sendMyEvent(me);
}
...
The event for the JComboBox does not seem to be fired. I registered an
ActionListener
the same way for two JTextField and that works. The JComboBox's event
should be fired
everytime the user changes the selected item. I would be very grateful
if someone could 
help me. Thanks and have a nice day,

christian