Here you can find the source of setColumnSizes(JTable table, double[] percentages)
public static void setColumnSizes(JTable table, double[] percentages)
//package com.java2s; /*/* www.j a va2 s . co m*/ * 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 3 of the * License, or (at your option) 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: * http://www.gnu.org/licenses/gpl.txt */ import java.awt.Dimension; import javax.swing.JTable; import javax.swing.table.TableColumn; public class Main { public static void setColumnSizes(JTable table, double[] percentages) { Dimension tableDim = table.getPreferredSize(); tableDim = table.getSize(); double total = 0; for (double t : percentages) total += t; table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setPreferredWidth((int) (tableDim.width * (percentages[i] / total))); //column.setMaxWidth((int) (tableDim.width * (percentages[i] / total))); //column.setMinWidth((int) (tableDim.width * (percentages[i] / total))); } } }