Java JTable Column Size Calculate setSize(JTable table, int columnIndex, int newSize)

Here you can find the source of setSize(JTable table, int columnIndex, int newSize)

Description

set Size

License

Apache License

Declaration

public static void setSize(JTable table, int columnIndex, int newSize) 

Method Source Code


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

import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.*;

public class Main {
    public static void setSize(JTable table, int columnIndex, int newSize) {
        TableColumn column = table.getColumnModel().getColumn(columnIndex);
        setSize(table, column, newSize);
    }/*  w ww. j  a  va  2s  .co m*/

    public static void setSize(JTable table, TableColumn column, int newSize) {
        newSize += getIntercellWidth(table);
        column.setMinWidth(newSize);
        column.setMaxWidth(newSize);
        column.setPreferredWidth(newSize);
        column.setWidth(column.getPreferredWidth());
    }

    public static int getIntercellWidth(JTable table) {
        return (int) table.getIntercellSpacing().getWidth();
    }

    public static int getPreferredWidth(Component component) {
        return (int) (component.getPreferredSize().getWidth() + 1);
    }
}

Related

  1. initColumnSizes(JTable table)
  2. initColumnSizes(JTable table, boolean[] show)
  3. initColumnSizes(JTable table, int rowStart, int rowEnd)
  4. initializeTableColumns(JTable table, int size[])
  5. pointOutsidePrefSize(JTable table, int row, int column, Point p)