List of utility methods to do JTable Column Resize
void | reSizeColumn(TableColumn col, int min, int preferred, int max) re Size Column col.setMinWidth(min); col.setPreferredWidth(preferred); col.setMaxWidth(max); |
void | resizeColumns(JTable table) Resize all columns in the table to fit widest row including header. if (table.getGraphics() == null) { return; DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); FontMetrics fm = table.getFontMetrics(renderer.getFont()); TableColumnModel mod = table.getColumnModel(); for (int iCol = 0; iCol < mod.getColumnCount(); iCol++) { TableColumn col = mod.getColumn(iCol); ... |
void | resizeColumnWidth(JTable table) Method ini digunakan untuk mengatur lebar kolom tabel agar otomatis menyesuaikan dengan isi pada kolom tersebut final TableColumnModel columnModel = table.getColumnModel(); for (int column = 0; column < table.getColumnCount(); column++) { int width = 50; for (int row = 0; row < table.getRowCount(); row++) { TableCellRenderer renderer = table.getCellRenderer(row, column); Component comp = table.prepareRenderer(renderer, row, column); width = Math.max(comp.getPreferredSize().width + 1, width); columnModel.getColumn(column).setPreferredWidth(width); |