Inserting a Column in a JTable Component

There is no insertColumn method like DefaultTableModel.insertRow() for inserting rows. In order to insert a column at a particular position, you must append the column using DefaultTable.addColumn() and then move the new column into the desired position. See Appending a Column to a JTable Component and Moving a Column in a JTable Component for more information.
int rows = 10;
int cols = 5;
JTable table = new JTable(rows, cols);

// Disable autoCreateColumnsFromModel
table.setAutoCreateColumnsFromModel(false);

// Add data

// Insert a new column at position 2 (becomes 3rd column)
insertColumn(table, "New Column", null, 2);

// Insert a new column at the end
insertColumn(table, "New Column", null, table.getColumnCount());

// Creates a new column at position vColIndex
public void insertColumn(JTable table, Object headerLabel,
                         Object[] values, int vColIndex) {
    // This method is defined in
    // Appending a Column to a JTable Component
    betterAddColumn(table, headerLabel, values);

    table.moveColumn(table.getColumnCount()-1, vColIndex);
}

Comments

30 Jun 2011 - 6:56pm by Anonymous (not verified)

fengying028 Casey GHD Lisseur hasLisseur GHD Midnight Deluxe Gift been GHD Lisseur Diamond 2010 charged Ghd Lisseur Rose with Edition limitée GHD Radiance Set seven Lisseur GHD Kiss counts, GHD Lisseur RARE Nouveau including Lisseur GHD MK4 Purple first Rose Lisseur GHD 2010 degree Ghd Lisseur Pure murder, Ghd Lisseur Salon aggravated child GHD lisseur abuse GHD édition Limitée and Ghd Lisseur Dark misleading Set cadeau GHD Midnight the police Lisseur GHD RARE in the GHD Hair Styling Set Lisseur death GHD Lisseur Red Lust of Lisseur GHD Purple Indulgence Caylee. If she Ghd Glattejern Danmark is Ghd Midnight Deluxe Danmark convicted of Ghd Midnight Gift Set first degree, Ghd Precious she could Ghd Pink Salg be sentenced Ghd pink Glattejern to death ghd-pink-2010-limited-editon-glattejern-p-8.html">Billige Ghd Pink by the Ghd Black Salg seven-woman, five-man Salg Ghd Diamond is expectedGhd Salon Salg to take Ghd Blue Salg another ghd-purple-indulgence-glattejern-p-16.html">Ghd Purple Salg 1-2 weeks before a verdict is reached.

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.