remove All Rows from JTable - Java Swing

Java examples for Swing:JTable Row

Description

remove All Rows from JTable

Demo Code


//package com.java2s;

import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

public class Main {
    /**// w w  w  .j a va  2s .  c o  m
     *
     * @param table
     */
    public static void removeAllRows(JTable table) {

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

        for (int row = 0; row < table.getRowCount(); row++) {
            model.removeRow(row);
        }

    }
}

Related Tutorials