Change the Name of a Column in a JTable in Java
Description
The following code shows how to change the Name of a Column in a JTable.
Example
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
//from www . ja v a2s .c o m
public class Main {
public static void main(String[] argv) throws Exception {
DefaultTableModel model = new DefaultTableModel();
JTable table = new JTable(model);
model.addColumn("Col1");
model.addColumn("Col2");
table.getColumnModel().getColumn(0).setHeaderValue("New Name");
table.getTableHeader().resizeAndRepaint();
}
}
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »