Here you can find the source of getPreferredHeaderWidth(JTable tbl, int iColumn)
Parameter | Description |
---|---|
tbl | a parameter |
iColumn | a parameter |
iColumn
of the given table
public static int getPreferredHeaderWidth(JTable tbl, int iColumn)
//package com.java2s; //it under the terms of the GNU Affero General Public License as published by import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; public class Main { /**/*from w ww .jav a 2s. co m*/ * calculates the preferred header width by asking the header renderer. * @param tbl * @param iColumn * @return the preferred header width for column <code>iColumn</code> of the given table */ public static int getPreferredHeaderWidth(JTable tbl, int iColumn) { TableColumn column = tbl.getColumnModel().getColumn(iColumn); TableCellRenderer renderer = column.getHeaderRenderer(); if (renderer == null) { renderer = tbl.getTableHeader().getDefaultRenderer(); } final Component compHeader = renderer.getTableCellRendererComponent(tbl, column.getHeaderValue(), false, false, 0, iColumn); int result = compHeader.getPreferredSize().width; result += tbl.getIntercellSpacing().getWidth(); // this is necessary for JRE 1.4+ return result; } }