Make a selection in one jcombobox enable a different jcombobox

老子叫甜甜 提交于 2020-02-06 09:24:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!