我在JBuilder中,用jComboBox做过这个,是两个的,三个应该也是一样的。下面是我的做法,不知道跟你情况一样不,给你参考一下。
添加jComboBox1的ActionPerformed事件,在该方法先判断选定的Item即jComboBox1.getSelectedItem().toString()是否变化,若变化了,则根据对jComboBox1的选择,查询出要在jComboBox2中显示的内容,然后先用jComboBox2.removeAllItems()方法删掉下一个相关下拉列表中的原有内容,再用jComboBox2.addItem()方法加入新的内容。
代码如下:
void jComboBox1_actionPerformed(ActionEvent e) {
    if(selectedItem != jComboBox1.getSelectedItem().toString()){
      selectedItem = jComboBox1.getSelectedItem().toString();
      jComboBox2.removeAllItems();
      parameterRow1.setString("queryColumn",selectedItem);
      queryDataSet1.refresh();
      queryDataSet1.open();
      rowCount1 = queryDataSet1.getRowCount();
      for(int i = 0;i < rowCount1;i++){
        jComboBox2.addItem(queryDataSet2.getString("displayColumn"));
        queryDataSet1.next();
      }
    }
}
再增加一个jComboBox也与此类似,只要在jComboBox2的ActionPerformed事件中做与上面类似的处理就可以了。

解决方案 »

  1.   

    http://www.csdn.net/Expert/TopicView1.asp?id=949181
      

  2.   

    我写了一个简单的例子,就用于连动显示省、市和县的关系,如下,你试运行一下,但愿对你有所帮助:
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.awt.*;public class Control3Combox extends JFrame {
      private JComboBox comb1 ;
      private JComboBox comb2 ;
      private JComboBox comb3 ;  private Vector provinces = new Vector();
      public Control3Combox() {
    //      comb1 = new JComboBox();
    //      comb2 = new JComboBox();
    //      comb3 = new JcomboBox();
         jb_init();
      }  private void jb_init(){
          // create the first province
          Province pro = new Province("Bei Jing");
          City  city1 = new City("海淀", pro);
          County coun1 = new County("hd1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("hd2", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("hd3",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          city1 = new City("chaoyang", pro);
          coun1 = new County("cy1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("cy2",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          city1 = new City("丰台", pro);
          coun1 = new County("ft1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("ft2",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          provinces.addElement(pro);      // create the second province
          pro = new Province("He Bei");
          city1 = new City("shijazhuang", pro);
          coun1 = new County("sjz1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("sjz2", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("sjz3",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          city1 = new City("handan", pro);
          coun1 = new County("hd1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("hd2",city1);
          city1.addCounty(coun1) ;
          coun1 = new County("hd3",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          city1 = new City("bbb", pro);
          coun1 = new County("bbb1", city1);
          city1.addCounty(coun1) ;
          coun1 = new County("bbb2",city1);
          city1.addCounty(coun1) ;
          pro.addCity(city1) ;
          provinces.addElement(pro);      // set data of each comboBox
          comb1 = new JComboBox(provinces);
          comb2 = new JComboBox(((Province)provinces.elementAt(0) ).getCities() );
          comb3 = new JComboBox(((City)(((ComboBoxModel)comb2.getModel()).getSelectedItem())).getCounties() );
          comb1.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent ae){
                  System.out.println(comb1.getSelectedItem());
                  System.out.println(((Province)comb1.getSelectedItem()).getCities() );
                  DefaultComboBoxModel model = new DefaultComboBoxModel(((Province)comb1.getSelectedItem()).getCities() );
                  comb2.setModel(model) ;
              }
          });      comb2.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent ae){
                if(comb2.getSelectedItem() != null){
                  System.out.println(comb2.getSelectedItem());
                  System.out.println(((City)comb2.getSelectedItem()).getCounties()  );
                  DefaultComboBoxModel model = new DefaultComboBoxModel(((City)comb2.getSelectedItem()).getCounties() );
                  comb3.setModel(model) ;
                }
              }
          });
          this.getContentPane() .setLayout(new BorderLayout()) ;
          getContentPane() .add(comb1,BorderLayout.WEST);
          getContentPane() .add(comb2, BorderLayout.CENTER );
          getContentPane() .add(comb3,BorderLayout.EAST );
          setSize(400,80);
          setVisible(true) ;  }  public static void main(String args[]){
          Control3Combox c3c = new Control3Combox();  }
    }class Province {
        private String name;
        private Vector cities;
        public Province(String name, Vector cities){
           this.name = name;
           this.cities= cities;
        }
        public Province (String name){
            this(name, new Vector());
        }
        public String toString(){
            return this.name;
        }
        public String getName(){return name;}    public void setName(String name){
          this.name= name;
        }    public Vector getCities(){return cities;}
        public void addCity (City oneCity){
            this.cities.addElement(oneCity);
        }
        public void setCities (Vector cities){
          this.cities = cities;
        }
    }class City {
        private String name;
        private Province province;
        private Vector counties;
        public City(String name, Province p, Vector counties){
            this.name = name;
            this.province =p;
            this.counties = counties;
        }
        public City(String name, Province p){
          this(name,p, new Vector());
        }    public String toString(){
            return this.name;
        }    public String getName(){return name;}    public void setName(String name){
          this.name = name;
        }    public Vector getCounties(){return this.counties;}
        public void addCounty(County oneCounty){
            this.counties.addElement(oneCounty);
        }
        public void setCounties(Vector counties){
            this.counties=counties;
        }}class County{
        private City city;
        private String name;
        public County(String name, City city){
            this.name = name;
            this.city = city;
        }    public String toString(){
            return name;
        }    public String getName(){return this.name;}    public void setName(String name){
          this.name= name;
        }}