set JTable Columns Width - Java Swing

Java examples for Swing:JTable Column

Description

set JTable Columns Width

Demo Code


//package com.java2s;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

public class Main {
    public static void setJTableColumnsWidth(JTable table, int... widths) {
        for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
            TableColumn column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth((int) widths[i]);
        }/*from www.  j  av a2  s . c  o m*/
    }
}

Related Tutorials