Java Utililty Methods JTable Row Delete

List of utility methods to do JTable Row Delete

Description

The list of methods to do JTable Row Delete are organized into topic(s).

Method

voiddeleteAllRows(JTable table)
delete All Rows
DefaultTableModel defaultTableModel = (DefaultTableModel) table.getModel();
defaultTableModel.setRowCount(0);
voiddeleteSelectedRows(JTable table)
delete Selected Rows
DefaultTableModel model = (DefaultTableModel) table.getModel();
int[] rows = table.getSelectedRows();
for (int rowIndex = 0; rowIndex < rows.length; rowIndex++) {
    model.removeRow(rows[rowIndex] - rowIndex);
voiddelSelectedRows(JTable table)
del Selected Rows
DefaultTableModel model = (DefaultTableModel) table.getModel();
if (model == null)
    return;
int selectedColumnCount = table.getSelectedRowCount();
for (int i = 0; i < selectedColumnCount; i++) {
    model.removeRow(table.getSelectedRow());
voidremoveAllRows(JTable table)
remove All Rows
if (table.getModel().getRowCount() <= 0)
    return;
TableModel model = table.getModel();
((DefaultTableModel) model).getDataVector().removeAllElements();
((DefaultTableModel) model).fireTableDataChanged();
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
table.setRowSorter(sorter);
sorter.setRowFilter(null);
...
voidremoveAllRows(JTable table)
remove All Rows
DefaultTableModel model = (DefaultTableModel) table.getModel();
for (int i = table.getRowCount() - 1; i > -1; i--) {
    model.removeRow(i);
voidremoveAllRows(JTable... tables)
remove All Rows
for (JTable table : tables) {
    DefaultTableModel model = (DefaultTableModel) table.getModel();
    while (model.getRowCount() > 0) {
        model.removeRow(0);
voidremoveAllRowsFromTable(DefaultTableModel model)
remove all existing rows from the table
while (model.getRowCount() > 0) {
    model.removeRow(0);
voidremoveRow(int index, JTable table)
Method removes row from table
if (index < table.getRowCount())
    ((DefaultTableModel) table.getModel()).removeRow(index);
voidremoveRow(JTable table, int row)
remove Row
DefaultTableModel model = (DefaultTableModel) table.getModel();
model.removeRow(row);
voidremoveRow(JTable table, int row)
remove Row
((DefaultTableModel) table.getModel()).removeRow(row);