//删除JTable表中选中记录。
DefaultTableModel   dtm=(DefaultTableModel)this.jTable1.getModel();   
  int[]   row   =   this.jTable1.getSelectedRows();   
  for(int   i=0;i<row.length;i++)   
  {   
dtm.removeRow(row[i]-i);//这儿要减i wrc
  }   

解决方案 »

  1.   

     Object[] options={"删除","取消"};
            int n=JOptionPane.showOptionDialog(this,"确定删除该餐桌信息吗?", "删除确认",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,options,options[0]);
            if(n==0){
                Connection conn = Connect.Connect();
                int RowSel[] = DishTable.getSelectedRows();
                String RowSelStr[] = new String[RowSel.length];
                for(int s = RowSel.length -1;s >= 0 ;s--){
                    RowSelStr[s] = (String)modelc.getValueAt(RowSel[s],0);
                    modelc.removeRow(RowSel[s]);
                }
                for(int i = 0;i<RowSel.length;i++){
                    RowSelStr[i] = "Delete  from menus where name = '"+RowSelStr[i]+"'";
                    //new DesksTask(conn).Delete(RowSelStr);
                    try {
                        new ForeMarg(conn).Delete(RowSelStr[i]);
                    } catch(Exception err) {
                        err.printStackTrace();
                    }
                }
                if(modelc.getRowCount() != 0){
                    DishTable.setRowSelectionInterval(RowSel[0],RowSel[0]);
                }
                
                JOptionPane.showMessageDialog(this,"删除成功","删除",JOptionPane.INFORMATION_MESSAGE);
            }else{
                JOptionPane.showMessageDialog(this,"删除失败","请查看",JOptionPane.INFORMATION_MESSAGE);
            }
      

  2.   


    对于Model,删除的话,会更新,也就是说 从 0~n 这样删除是不对的,和实际删除的数据不一致。应该从 n~0 删除,这样Model变化不会影响到记录的Index
      

  3.   

    remove 了 界面要重新刷新下吧
      

  4.   

    我都是这么删的://删除JTable表中选中记录。
    DefaultTableModel  dtm=(DefaultTableModel)this.jTable1.getModel(); 
    int[]  row  =  this.jTable1.getSelectedRows(); 
    for(int  i=row.length-1; i >=0; i--) { 
        dtm.removeRow(row[i]);
    }
      

  5.   

    我觉得支持11楼,还是从数据源里面删除.使用自己的model,重写删除的方法,这样条理清晰.
    呵呵,一家之言.
      

  6.   

    Did you want to delete the data only from JTable or in Database as well?