问题
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...
回答1:
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.
来源:https://stackoverflow.com/questions/5376546/make-a-selection-in-one-jcombobox-enable-a-different-jcombobox