Changing the Name of a Column in a JTable Component

DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); // Create 2 columns model.addColumn("Col1"); model.addColumn("Col2"); // Change name of first visible column int vColIndex = 0; table.getColumnModel().getColumn(vColIndex).setHeaderValue("New Name"); // Force the header to resize and repaint itself table.getTableHeader().resizeAndRepaint();

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.