Java Utililty Methods JTable Column Size Calculate

List of utility methods to do JTable Column Size Calculate

Description

The list of methods to do JTable Column Size Calculate are organized into topic(s).

Method

voidadjustColumnSizes(JTable table, int column, int margin)
Method sets columns width to the widest value
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
TableColumn col = colModel.getColumn(column);
int width;
TableCellRenderer renderer = col.getHeaderRenderer();
if (renderer == null)
    renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
width = comp.getPreferredSize().width;
...
voidautoSizeCols(JTable table)
auto Size Cols
if (table == null || table.getColumnCount() == 0) {
    return;
TableColumnModel columnModel = table.getColumnModel();
for (int col = 0; col < table.getColumnCount(); col++) {
    int maxwidth = 0;
    for (int row = 0; row < table.getRowCount(); row++) {
        TableCellRenderer rend = table.getCellRenderer(row, col);
...
voidautoSizeTableColumns(JTable table)
auto Size Table Columns
for (int column = 0; column < table.getColumnCount(); column++) {
    int columnWidth = 0;
    for (int row = 0; row < table.getRowCount(); row++) {
        TableCellRenderer renderer = table.getCellRenderer(row, column);
        Component comp = table.prepareRenderer(renderer, row, column);
        columnWidth = Math.max(comp.getPreferredSize().width, columnWidth);
    table.getColumnModel().getColumn(column).setPreferredWidth(columnWidth);
...
intcalcColumnWidth(JTable table, int col)
Calculates the optimal width for the column of the given table.
int width = calcHeaderWidth(table, col);
if (width == -1)
    return width;
TableColumnModel columns = table.getColumnModel();
TableModel data = table.getModel();
int rowCount = data.getRowCount();
TableColumn column = columns.getColumn(col);
try {
...
voidcalcColumnWidths(final JTable table)
Calculates and sets the each column to it preferred size.
calcColumnWidths(table, 10);
voidcalcColumnWidths(final JTable table)
Calculate table column width according to contents.
final JTableHeader header = table.getTableHeader();
TableCellRenderer defaultHeaderRenderer = null;
if (header != null) {
    defaultHeaderRenderer = header.getDefaultRenderer();
TableColumnModel columns = table.getColumnModel();
TableModel data = table.getModel();
int margin = columns.getColumnMargin(); 
...
voidcalcColumnWidths(JTable table)
calc Column Widths
JTableHeader header = table.getTableHeader();
TableCellRenderer defaultHeaderRenderer = null;
if (header != null) {
    defaultHeaderRenderer = header.getDefaultRenderer();
TableColumnModel columns = table.getColumnModel();
TableModel data = table.getModel();
int margin = columns.getColumnMargin(); 
...
voidcalcColumnWidths(JTable table)
Setzt die Breite der TableColumns.
JTableHeader header = table.getTableHeader();
TableCellRenderer defaultHeaderRenderer = null;
if (header != null)
    defaultHeaderRenderer = header.getDefaultRenderer();
TableColumnModel columns = table.getColumnModel();
TableModel data = table.getModel();
int margin = columns.getColumnMargin(); 
int rowCount = data.getRowCount();
...
intcalculateColumnWidth(JTable table, int columnIndex)
calculate Column Width
int width = 0; 
int rowCount = table.getRowCount();
for (int i = 0; i < rowCount; i++) {
    TableCellRenderer renderer = table.getCellRenderer(i, columnIndex);
    Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(i, columnIndex), false,
            false, i, columnIndex);
    int thisWidth = comp.getPreferredSize().width;
    if (thisWidth > width) {
...
intcalculateColumnWidth(JTable table, int columnIndex)
Calculates the required width of a table column
int width = 0;
int rowCount = table.getRowCount();
TableCellRenderer renderer = table.getTableHeader().getDefaultRenderer();
Component comp = renderer.getTableCellRendererComponent(table, table.getColumnName(columnIndex), false,
        false, 0, columnIndex);
width = comp.getPreferredSize().width;
for (int i = 0; i < rowCount; i++) {
    renderer = table.getCellRenderer(i, columnIndex);
...