List of utility methods to do JTable Auto Resize
int | autoResizeTable(JTable aTable, int columnPadding) auto Resize Table int columnCount = aTable.getColumnCount(); int currentTableWidth = aTable.getWidth(); int tableWidth = 0; Dimension cellSpacing = aTable.getIntercellSpacing(); if (columnCount > 0) int columnWidth[] = new int[columnCount]; for (int i = 0; i < columnCount; i++) { ... |
void | autoResizeTableColWidths(JTable table) Adjust the widths of each column of a table to match the max width of each value in the table. table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); int fullsize = 0; Container parent = table.getParent(); if (null != parent) { fullsize = Math.max(parent.getPreferredSize().width, parent.getSize().width); int sumWidths = 0; for (int i = 0; i < table.getColumnCount(); i++) { ... |
void | autoResizeTableRowHeights(JTable table) Adjust the heights of each row of a table to match the max height of each value in the table. table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) { int height = 0; for (int colIndex = 0; colIndex < table.getColumnCount(); colIndex++) { DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(colIndex); TableCellRenderer renderer = table.getCellRenderer(rowIndex, colIndex); Object value = table.getValueAt(rowIndex, colIndex); ... |