首页 > 解决方案 > Swing中的多个依赖组合框

问题描述

我的学生注册代码要求,根据所选学科选择课程。
例如:学科毕业后启用多个流,如果我们选择“法律”,则必须在课程组合框中显示与法律相关的课程。我已经实现了依赖于学科组合框的流组合框。所有这些组合框的任何最佳方法。

private void Combo_desciplineActionPerformed(java.awt.event.ActionEvent evt) {                                                 
         // TODO add your handling code here:
         if(Combo_descipline.getSelectedItem().equals("Certificate")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("Diploma")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.addItem("Healthcare and Allied Sciences");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Media and Mass Communication");
             Combo_stream.addItem("Pharmacy");
             Combo_stream.addItem("Polytechnic");
             Combo_stream.addItem("Yoga and Vedic Science");  
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("Integreted")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Arts");
             Combo_stream.addItem("Commerce");
             Combo_stream.addItem("Computer Science and IT");
             Combo_stream.addItem("Education");
             Combo_stream.addItem("Engineering and Technology");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Law");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Science");    
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("Lateral Entry")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Engineering and Technology");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Polytechnic");     
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("PG")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Arts");
             Combo_stream.addItem("Commerce");
             Combo_stream.addItem("Computer Science and IT");
             Combo_stream.addItem("Education");
             Combo_stream.addItem("Engineering and Technology");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.addItem("Healthcare and Allied Sciences");
             Combo_stream.addItem("Home Science");
             Combo_stream.addItem("Law");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Media and Mass Communication");
             Combo_stream.addItem("Pharmacy");
             Combo_stream.addItem("Physiotherapy");
             Combo_stream.addItem("Science");             
             Combo_stream.addItem("Yoga and Vedic Science");
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("PG Diploma")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Arts");             
             Combo_stream.addItem("Computer Science and IT");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.addItem("Healthcare and Allied Sciences");
             Combo_stream.addItem("Home Science");
             Combo_stream.addItem("Law");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Media and Mass Communication");
             Combo_stream.addItem("Pharmacy");
             Combo_stream.addItem("Science");             
             Combo_stream.addItem("Yoga and Vedic Science");
             Combo_stream.setSelectedItem(null);
         }
          else if(Combo_descipline.getSelectedItem().equals("Phd/MPhil")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Arts");  
             Combo_stream.addItem("Commerce");
             Combo_stream.addItem("Computer Science and IT");
             Combo_stream.addItem("Education");             
             Combo_stream.addItem("Engineering and Technology");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.addItem("Healthcare and Allied Sciences");
             Combo_stream.addItem("Home Science");
             Combo_stream.addItem("Law");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Media and Mass Communication");
             Combo_stream.addItem("Pharmacy");
             Combo_stream.addItem("Science");             
             Combo_stream.addItem("Yoga and Vedic Science");
             Combo_stream.setSelectedItem(null);
         }
         else if(Combo_descipline.getSelectedItem().equals("UG")){
             Combo_stream.removeAllItems();
             Combo_stream.addItem("Agriculture");
             Combo_stream.addItem("Arts");
             Combo_stream.addItem("Commerce");
             Combo_stream.addItem("Computer Science and IT");
             Combo_stream.addItem("Education");
             Combo_stream.addItem("Engineering and Technology");
             Combo_stream.addItem("Fashion Design and Technology");
             Combo_stream.addItem("Film Technology");
             Combo_stream.addItem("Healthcare and Allied Sciences");
             Combo_stream.addItem("Home Science");
             Combo_stream.addItem("Law");
             Combo_stream.addItem("Management");
             Combo_stream.addItem("Media and Mass Communication");
             Combo_stream.addItem("Pharmacy");
             Combo_stream.addItem("Physiotherapy");
             Combo_stream.addItem("Science");             
             Combo_stream.addItem("Yoga and Vedic Science");             
             Combo_stream.setSelectedItem(null);
         }
         
    } 

它应该如下所示:

样本

标签: javaswingjcombobox

解决方案


推荐阅读