Java JTable Header adjustHeader(JTable table)

Here you can find the source of adjustHeader(JTable table)

Description

adjust Header

License

Apache License

Declaration

public static void adjustHeader(JTable table) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.awt.Component;

import javax.swing.JTable;

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

public class Main {

    public static void adjustHeader(JTable table) {

        TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {

            TableColumn column = table.getColumnModel().getColumn(i);

            Component header = headerRenderer.getTableCellRendererComponent(table, column.getHeaderValue(), false,
                    false, 0, i);/*  ww  w .j av a  2 s  .  c om*/

            column.setPreferredWidth(header.getPreferredSize().width + 8);
        }
    }
}

Related

  1. AddToTable(JTable tbl, Object[] obj, boolean head)
  2. calcHeaderWidth(int col)
  3. calcHeaderWidth(JTable table, int col)
  4. cleanHeaderCells(JTable table)
  5. createTableHeaderEmptyColumnPainter(final JTable table)