I'm trying to write a program which will take the input from one drop-down box, and use that to calculate the drop down box for another field, but I keep running into a problem. To make it work, I have to remove all items from on JComboBox, before refilling it, but this causes the program to throw an exception.
jbox1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
autoCalc();
String s = jbox1.getSelectedItem().toString();
workS.set1(s);
jbox2.removeAllItems();
for(int i = 0; i <= workS.jbox1.getSelectedItem; i++)
{
String temp = ("" + i);
jbox2.addItem(temp);
}
autoCalc();
}
});
jbox2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
autoCalc();
String s = jbox2.getSelectedItem().toString();
workS.set2(s);
autoCalc();
}
});
As far as I can tell, removing all items from jbox2 calls the jbox2 actionlistener, which realises that the field is empty and throws an exception. Does anyone have a way around this?