column JTable Header Width - Java Swing

Java examples for Swing:JTable Column

Description

column JTable Header Width

Demo Code


//package com.java2s;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

public class Main {
    static private int columnHeaderWidth(JTable l_Table, TableColumn col) {
        TableCellRenderer renderer = l_Table.getTableHeader()
                .getDefaultRenderer();//  w  ww .j  ava  2s  .com

        Component comp = renderer.getTableCellRendererComponent(l_Table,
                col.getHeaderValue(), false, false, 0, 0);
        return comp.getPreferredSize().width;
    }
}

Related Tutorials