Java JTable Column Width Set setTableColWidths(JTable table, int... colWidths)

Here you can find the source of setTableColWidths(JTable table, int... colWidths)

Description

set Table Col Widths

License

Open Source License

Declaration

public static void setTableColWidths(JTable table, int... colWidths) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.*;

import javax.swing.table.*;

public class Main {
    public static void setTableColWidths(JTable table, int... colWidths) {
        if ((table != null) && (colWidths != null)) {
            TableColumnModel tcm = table.getColumnModel();
            if (tcm != null) {
                int n = Math.min(tcm.getColumnCount(), colWidths.length);
                for (int i = 0; i < n; i++) {
                    TableColumn c = tcm.getColumn(i);
                    if (c != null)
                        c.setPreferredWidth(colWidths[i]);
                }//w  w w .  ja  v a2  s  .  com
            }
        }
    }
}

Related

  1. SetPreferedColumnWIdth(JTable table, int[] widths)
  2. setPreferredColumnWidths(final JTable table, final float[] columnWeigths, final boolean includeHeader)
  3. setPreferredRowHeights(final JTable table)
  4. setRelativeColumnWidths(JTable table, int... widths)
  5. setTableColWidth(JTable table, int column, int width)
  6. updateTableColumnWidth(JTable table)