How to remove all columns? Thanks.
You must remove the data from the TableModel used for the table. If using the DefaultTableModel , just set the row count to zero. This will delete the rows and fire the TableModelEvent to update the GUI. JTable table; …
Removing a column from a JTable means deleting the column containing the data. For removing the column, use the removeColumn() method, for this, you need the index of column that have to be deleted from the JTable.
If you want to remove columns from the middle of the model, then you will need to: extend the DefaultTableModel and create your own removeColumn(int column) method. This method would need to loop through every row in the Vector and use the Vector. remove(int) method to remove the column for ever row.
If you're using DefaultTableModel, set column count to zero.
Faster Way::Dynamic Remove all the Column on JTable
//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);
Before code on this Example
//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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With