F
f
I have two JComboBox, box1 and box2. box2 is dependent on box1.
1. I populate box1 with two selections "Color" and "Shape"
2. box2 is blank.
3. If use select "Color" in box1, I populate box2 with selections
"Red" and "Green".
4. If use select "Shape" in box1, I populate box2 with two selections
"Circle" and "Rectangle".
5. User select box2...
I handle the itemStateChanged event of both box1 and box2, here is my
code"
void box1_itemStateChanged(ItemEvent e) {
box2.removeAllItems();
String item = box1.getSelectedItem().toString();
if (item.equalsIgnoreCase("Color")){
box2.addItem("Red");
box2.addItem("Green");
}else{
box2.addItem("Cirlce");
box2.addItem("Rectangle");
}
}
void box2_itemStateChanged(ItemEvent e) {
String item = box2..getSelectedItem.toString();
...
}
I found a problem here. When I call box2.addItem("Red"), the method
box2_itemStateChanged was called and the program goes inside this
method and everything was messed up. How do I block box2 from sending
event where I am in box1_itemStateChanged(ItemEvent e) populating
box2?
Thanks,
ff
1. I populate box1 with two selections "Color" and "Shape"
2. box2 is blank.
3. If use select "Color" in box1, I populate box2 with selections
"Red" and "Green".
4. If use select "Shape" in box1, I populate box2 with two selections
"Circle" and "Rectangle".
5. User select box2...
I handle the itemStateChanged event of both box1 and box2, here is my
code"
void box1_itemStateChanged(ItemEvent e) {
box2.removeAllItems();
String item = box1.getSelectedItem().toString();
if (item.equalsIgnoreCase("Color")){
box2.addItem("Red");
box2.addItem("Green");
}else{
box2.addItem("Cirlce");
box2.addItem("Rectangle");
}
}
void box2_itemStateChanged(ItemEvent e) {
String item = box2..getSelectedItem.toString();
...
}
I found a problem here. When I call box2.addItem("Red"), the method
box2_itemStateChanged was called and the program goes inside this
method and everything was messed up. How do I block box2 from sending
event where I am in box1_itemStateChanged(ItemEvent e) populating
box2?
Thanks,
ff