Java JTable Column ajustarAnchoColumnas(JTable table)

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

Description

ajustar Ancho Columnas

License

Open Source License

Declaration

public static void ajustarAnchoColumnas(JTable table) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

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

public class Main {
    public static void ajustarAnchoColumnas(JTable table) {
        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);
                Object value = table.getValueAt(row, col);
                Component comp = rend.getTableCellRendererComponent(table,
                        value, false, false, row, col);
                maxwidth = Math//from ww  w . j a va  2  s . c  om
                        .max(comp.getPreferredSize().width, maxwidth);
            } // para fila

            TableColumn column = columnModel.getColumn(col);
            column.setPreferredWidth(maxwidth);
        } // para columnas

    }
}

Related

  1. aceptarTeclaPresionada(KeyEvent e, JTable pTabla, JTextField pTextoDeBusqueda, int pColumna)
  2. addSpaceSelection(final JTable table, final int column)
  3. buscarDescripcion(KeyEvent e, JTable pTabla, JTextField pTextoDeBusqueda, int pColumna)
  4. cloneTableColumn(TableColumn c)
  5. cloneTableColumnModel(TableColumnModel m)
  6. columnAt(final JTable table, final Point p, final Class columnClazz)