如何删除所有列?谢谢。

最佳答案


//JTable variable name is jTable1_info....
model_info=(DefaultTableModel)jTable1_info.getModel();
//Clear all the column name on jtable jpanel-4
model_info.setColumnCount(0);

在此示例上的代码之前
//import the DefaultTableModel
import javax.swing.table.DefaultTableModel;

public final class homepage extends javax.swing.JFrame implements ActionListener
{
    DefaultTableModel model_info;
    public homepage() throws InterruptedException
    {
        initComponents();
        create_column();//call method create jtable column names
    }
}
private void create_column()
{
    model_info=(DefaultTableModel)jTable1_info.getModel();
    model_info.addColumn("Column_Name");
    model_info.addColumn("Column_type");
    model_info.addColumn("Column_size");
}

10-08 13:21