configure JTable Column - Java Swing

Java examples for Swing:JTable Column

Description

configure JTable Column

Demo Code


//package com.java2s;

import javax.swing.JTable;

import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

public class Main {
    public static void configureColumn(JTable table, int columnNumber,
            Integer width, TableCellRenderer renderer,
            TableCellEditor editor) {
        TableColumn column = table.getColumnModel().getColumn(columnNumber);
        if (width != null)
            column.setMaxWidth(width);/*w  ww.ja v  a2 s .c  o  m*/
        if (renderer != null)
            column.setCellRenderer(renderer);
        if (editor != null)
            column.setCellEditor(editor);
    }
}

Related Tutorials