JAVA: eliminate item from combobox ???
Hey,
I having these 5 comboboxes. On selecting comboxox1 I need to eliminate the same item from the other 4 remaining comboboxes, so that it wont be possible to choose the same item more than once.Yet the 5 comboboxes are distinct and cannot be put into one combo.
Hey any code or ideas are very much appreciated. Thanks loads
Re: JAVA: eliminate item from combobox ???
Which part are you having trouble with? To check when the selection was changed in a combo you need to implement an ItemListener like this :
Code:
class MyItemListener implements ItemListener {
Panel cp;
Choice c;
public MyItemListener(Choice c, Panel cp) {
this.cp = cp;
this.c = c;
}
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED){
//do stuff here depending on the selection, change the items in the other combos
//CardLayout LM=(CardLayout)cp.getLayout();
//LM.show(cp,(String)e.getItem());
}
}
}
And in your main code :
Code:
c.addItemListener(new MyItemListener(c,cards));
Re: JAVA: eliminate item from combobox ???
surely that is pretty easy, write a wrapper that takes in two combo boxes, n and n + 1
add change listeners to n, then when there is a change you know which item to remove from n+ 1..
where is the hardship?!