Set width of column in a JTable to 'width' pixels. - Java Swing

Java examples for Swing:JTable Column

Description

Set width of column in a JTable to 'width' pixels.

Demo Code


//package com.java2s;

import javax.swing.JTable;

public class Main {
    /**/*from ww w . j a  v a 2  s  .  c o  m*/
     * Set width of column in a table to 'width' pixels.
     *
     * @param table
     * @param column
     * @param width
     */
    public static void setColumnSize(JTable table, int column, int width) {
        table.getColumnModel().getColumn(column).setMinWidth(width);
        table.getColumnModel().getColumn(column).setMaxWidth(width);
    }
}

Related Tutorials