Jtable删除多行

 

 

        int[] selections = table.getSelectedRows();
        //和tableModel统一序号
        for (int i = 0; i < selections.length; i++) {
            selections[i] = table.convertRowIndexToModel(selections[i]);
        }
        /**
         * 删除数据库的
         */
        for (int i : selections) {
            Vector line = new Vector();
            //获取选择行的数据
            line = (Vector) table_data.get(i);
            //删除
            testService.delete(new Object(line.get(0)));
        }
        /**
         * 删除界面上的
         */
        //获取model
        DefaultTableModel df = (DefaultTableModel) table.getModel();
        //反向删除
        for (int i = selections.length; i > 0; i--) {
            df.removeRow(table.getSelectedRow());
        }
 

你可能感兴趣的:(jtable)