hide column by index in JTable

/**
 * 
 * @param columnIndex
 */
private void hideColumnByIndex(JTable table, int columnIndex) {
	TableColumnModel tcm = table.getColumnModel();
	TableColumn tc = tcm.getColumn(columnIndex);
	// tc.setResizable(false);
	tc.setWidth(0);
	tc.setPreferredWidth(0);
	tc.setMaxWidth(0);
	tc.setMinWidth(0);
	table.getTableHeader().getColumnModel().getColumn(columnIndex)
			.setMaxWidth(0);
	table.getTableHeader().getColumnModel().getColumn(columnIndex)
			.setMinWidth(0);
}

 

你可能感兴趣的:(jtable)