我想实现这样一个功能,一个Jtable里面的每一行,前面几列都是字符串数据,最后一列是一个复选框,我想把其中几行的复选框选中,然后把这几行的数据一次存到数据库中去,请问有没有这样的方法呢?好像要通过判断selects,然后循环什么的,有没有人能解答一下,最好把代码也发上来,谢谢啦!
ps:Jtable 最好是用defaulttablemodel或者abstracttablemodel来实现的!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主截止到2008-06-17 22:19:55的汇总数据:
    发帖数:2
    结贴数:0
    结贴率: 0.00%
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    .....楼主啊,
    大作业吗? api看下吧,真的
      

  3.   

    看不太懂阿,不知道api该怎么用呢,所以才来请教的呀,唉。。
      

  4.   

     Object getValueAt(int row, int column) 
              返回 row 和 column 位置的单元格值。 
    相应的行和列传进去  转成Boolean 
    Boolean boo = (Boolean)tb.getValueAt(row,col);
    if(boo.boolValue()){.....
      

  5.   

    ....我觉得我提示得差不多了,不过遍历每一行,应该会吧。
    int rows = table.getRowCount();
    for循环,
      

  6.   

    首先:最后一列的renderer要改,改成BooleanRenderer之类的 
    在BooleanRenderer里面得到的返回值,即value的值为boolean型 
    这样,在存库的时候,对最后一列的单元格循环,得到选中的行,之后进行你的存库操作 
    JTable table = new JTable();
            int columnCount = table.getColumnCount();
            for (int i = 0; i < table.getRowCount(); i++) {
                if((Boolean)table.getValueAt(i, columnCount)){
                    //save to DB
                }
            }