Clean the JTable, only apply to DefaultTableModel - Java Swing

Java examples for Swing:JTable Model

Description

Clean the JTable, only apply to DefaultTableModel

Demo Code


//package com.java2s;

import javax.swing.table.DefaultTableModel;

import javax.swing.table.TableModel;

public class Main {
    /**//from  w w w  . j av a2  s .co  m
     * Clean the table, only apply to DefaultTableModel
     * 
     * @param tableModel
     */
    public static void removeAllRows(TableModel tableModel) {
        if (tableModel instanceof DefaultTableModel) {
            DefaultTableModel dtm = (DefaultTableModel) tableModel;
            dtm.setRowCount(0);
        }
    }
}

Related Tutorials