Java JTable Column Width Set setColumnWidth(JTable table, int... width)

Here you can find the source of setColumnWidth(JTable table, int... width)

Description

set Column Width

License

Open Source License

Declaration

public static void setColumnWidth(JTable table, int... width) 

Method Source Code

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

import javax.swing.JTable;

import javax.swing.table.TableColumnModel;

public class Main {
    public static void setColumnWidth(JTable table, int... width) {
        TableColumnModel columnModel = table.getColumnModel();
        int length = width.length;
        int columnCount = table.getColumnCount();

        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

        for (int i = 0; i < length && i < columnCount; i++) {
            columnModel.getColumn(i).setPreferredWidth(width[i]);
        }/* ww  w . jav  a2 s .  c o m*/
    }
}

Related

  1. setColumnSizes(JTable table, double[] percentages)
  2. setColumnsSize(TableColumnModel cm, int tablesize)
  3. setColumnWidth(JTable table, int columnIdx, int width)
  4. setColumnWidth(JTable table, int columnIndex, int preferredWidth)
  5. setColumnWidth(JTable table, int columnNumber, int width)
  6. setColumnWidth(JTable table, int[] colWidth)
  7. setColumnWidths(int[] preferredColWidths, int[] maxColWidths, int[] minColWidths, TableColumnModel columnModel, boolean[] columnsShowing)
  8. setColumnWidths(JTable p_Table, int[] p_ColumnWidths)
  9. setColumnWidths(JTable table, Insets insets, boolean setMinimum, boolean setMaximum)