Here you can find the source of setColumnWidth(JTable table, int[] colWidth)
Parameter | Description |
---|---|
table | table to set the column width |
colWidth | array with the new column width |
public static void setColumnWidth(JTable table, int[] colWidth)
//package com.java2s; /*/* www . j a va 2 s . c o m*/ * Copyright (C) 2008 Michael Romankiewicz * microm at users.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import javax.swing.JTable; import javax.swing.table.TableColumnModel; public class Main { /** * Set the widths for the columns of table * * @param table * table to set the column width * @param colWidth * array with the new column width */ public static void setColumnWidth(JTable table, int[] colWidth) { TableColumnModel tcm = table.getColumnModel(); for (int col = 0; col < tcm.getColumnCount(); col++) { if (col < colWidth.length) { tcm.getColumn(col).setPreferredWidth(colWidth[col]); } } table.doLayout(); } }