Clear All JTable - Java Swing

Java examples for Swing:JTable

Description

Clear All JTable

Demo Code


//package com.java2s;

import javax.swing.table.DefaultTableModel;

public class Main {
    public static void ClearAllTable(javax.swing.JTable table) {
        //first clear the table
        while (table.getRowCount() > 0)
            ((DefaultTableModel) table.getModel()).removeRow(0);
        //then make 4 new empty row
        for (int i = 0; i < 4; i++)
            ((DefaultTableModel) table.getModel()).addRow(new Object[] {
                    null, null, null, null, null, null, null, null, null,
                    null });/*from w  w  w  .j a v a  2 s  .  c  o  m*/
    }
}

Related Tutorials