delete JTable Select Row - Java Swing

Java examples for Swing:JTable Row

Description

delete JTable Select Row

Demo Code


//package com.java2s;
import java.util.Arrays;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class Main {
    public static void deleteSelectRow(JTable table) {
        int[] rows = table.getSelectedRows();

        deleteRows(table, rows);//from  w  ww.j  av a2s. com
    }

    public static void deleteRows(JTable table, int[] rows) {
        if (rows == null)
            return;

        Arrays.sort(rows);

        DefaultTableModel model = (DefaultTableModel) table.getModel();

        for (int i = rows.length - 1; i >= 0; i--) {
            model.removeRow(rows[i]);
        }
    }
}

Related Tutorials