Graham
Graham

Reputation: 1

Make a selection in one jcombobox enable a different jcombobox

I have 7 jcomboboxes that all start with the same default selection. How do I make then next one enabled when something other than the default if selected in the preceding jcombobox?

        if ( ! (custData1.equals("Please Select a Customer from the dropdown menu")) ){
        custData2.setEnabled(true);
        if ( ! (custData2.equals("Please Select a Customer from the dropdown menu")) ){
            custData3.setEnabled(true);
            if ( ! (custData3.equals("Please Select a Customer from the dropdown menu")) ){
            custData4.setEnabled(true);
            if ( ! (custData4.equals("Please Select a Customer from the dropdown menu")) ){
            custData5.setEnabled(true);
            if ( ! (custData5.equals("Please Select a Customer from the dropdown menu")) ){
            custData6.setEnabled(true);
            if ( ! (custData6.equals("Please Select a Customer from the dropdown menu")) ){
            custData7.setEnabled(true);
            }
           }
          }
         }
        }
    }

This doesn't seem to work...

Upvotes: 0

Views: 468

Answers (1)

jzd
jzd

Reputation: 23629

Create a custom JComboBox by extends JComboBox. Make that class take in a reference to the preceding combobox. Have it and itself as an ActionListener to the preceding box and whenever an item is selected it should enable/disable itself.

Upvotes: 1

Related Questions