在JTable里的某一列的每一项都隐藏的对应一个jComboBox,怎么弄啊,很麻烦,关键是jTable的数据也是从数据库中查到的,怎么能再加JComboBox呢?不会做,请大家帮帮忙

解决方案 »

  1.   

    网上例子太多了,不细说,看链接,或自个搜。
    http://zhidao.baidu.com/question/40840960.html?fr=qrl
      

  2.   

    不是那么简单啊 首先是从数据库中查询出来,把数据显示在JTable中,然后,在显示的第8列中的字段加上JComboBox,而且还是隐藏的,我现在困难就是在添加JComboBox的item时,怎么动态的加上从数据库查出的信息,让数据库查出来的这条字段显示,而其他的项不显示?麻烦啊
      

  3.   

    public class TestAll extends JFrame{
    String[] select1={"a","b","c"};
    String[] select2={"1","2","3"};
    String[] select3={"!","@","#"};
    String[][] b={{"a","1","!"},{"b","2","@"},{"c","3","#"}};
    public TestAll(){
    init();
    }
    private void init(){
    Object[] column={"协作工艺类型","协作承制单位","负责人"};
    String[][] rowData={{"a","b","c"},{"1","2","3"},{"!","@","#"},};
    JTable jt=new JTable(b,column);
    jt.getTableHeader().setReorderingAllowed(false);
    TableColumnModel tcm=jt.getColumnModel();
    for(int i=0;i<jt.getColumnCount();i++){

    JComboBox com=new JComboBox(rowData[i]);
    tcm.getColumn(i).setCellEditor(new DefaultCellEditor(com)); //实现在哪一行加JComboBox
    }
    JScrollPane jsp=new JScrollPane(jt);
    JPanel jp=new JPanel(new BorderLayout());
    jp.add(jsp);
    this.getContentPane().add(BorderLayout.CENTER,jp);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.pack();
    this.show();
    }
    public static void main(String[] args){
    new TestAll();
    }
    }
      

  4.   

    我的问题不是怎么加JComboBox,我的JTable的第8项是从数据库查出来的list遍历出来的第8项,正好也是你加进去的JComboBox的某一项,怎么在遍历list时和JComboBox结合啊?
      

  5.   

    你是不是想得到在jtable里面改变后,得到的值?
    for (int i = 0; i < tm.getRowCount(); i++) {
    for (int j = 0; j < tm.getColumnCount(); j++) {
    System.out.println(tm.getValueAt(i, j));
    }
    }
      

  6.   

    在jcombobox.addActionListener中加中table.updateUI试下看!