views:

18

answers:

0

I have 2 combo boxes, one dependent on another. For the second combo I define custom renderer and it's disabled. It should enable when some items of the 1st combo is selected, but it clears all values instead. The problem is that the values are set but are not rendered.

In constructor:

comboBoxes[1].setEnabled(false);
comboBoxes[1].setRenderer(new CellRenderer());
Vector<SupplierTO> suppliers = getSuppliers();
Vector<SupplierTO> suppliers = getSuppliers();
suppliers.add(0, new SupplierTO("Choose supplier", "", "", ""));
ComboBoxModel cbm = new DefaultComboBoxModel(suppliers);
comboBoxes[1].setModel(cbm);

comboBoxes[0].addActionListener(new ComboListener());

In ComboListener Action listerner:

public void actionPerformed(ActionEvent e) {
    if (comboBoxes[0].getSelectedIndex() == 1 || comboBoxes[0].getSelectedIndex() == 5) {
comboBoxes[1].setEnabled(true);
}else{
comboBoxes[1].setEnabled(false);
  }