java - JComboBox Action listener -
i'm having problem. have multiple jcomboboxes (5 total).
to each combobox add actionlistener, same actionlistener of them, called:
comboboxactionperformed(java.awt.event.actionevent e)
and when action performed @ event (e) , do:
jcombobox c = ((jcombobox)e.getsource()); //do work relating c thats combobox triggered.
but problem when change in of comboboxes action triggered last combo box attaching actionlistner.
anyone have idea?
i switched itemlistner. im doing a
class myactionlistner implements itemlistener { //stuff @override public void itemstatechanged(itemevent evt) { //do stuff } } public jcombobox createcombo() { jcombobox box = new jcombobox(); box.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "val1", "val2","val3" })); rulesactionlistner actionl = new rulesactionlistner(); box.additemlistener(actionl); return box; }
and createcombo gets called multiple times regardless of combo box item changed in side itemstatechanged method comming last combo box created
createcombo called @ runtime, have variable number of comboboxes.
add separate action listeners instead of having 1 action listener run through if statements each call. section of code have logic has bug causing last combo box selected. (maybe else
statement should else if
, etc.).
separating out more oo , more flexible long term.
Comments
Post a Comment