How do you remove selected rows from a JTable?

前端 未结 18 1170
情话喂你
情话喂你 2020-12-30 03:26

I\'ve tried this:

public void removeSelectedFromTable(JTable from)
{
    int[] rows = from.getSelectedRows();
    TableModel tm= from.getModel();

    while(         


        
18条回答
  •  礼貌的吻别
    2020-12-30 04:13

    try this is perfect work and simple

    DefaultTableModel df1 = (DefaultTableModel) jTable1.getModel();
        int rs[] = jTable1.getSelectedRows();
        for (int i = rs.length-1; i >=0 ; i--) {
    
            int k = rs[i];
    
            df1.removeRow(k);
    
        }
    

提交回复
热议问题