List of utility methods to do JTable Column Width Get
int[] | getColumnWidth(JTable table) get Column Width int[] columnWidth = new int[table.getColumnModel().getColumnCount()]; for (int i = 0; i < columnWidth.length; i++) { columnWidth[i] = table.getColumnModel().getColumn(i).getPreferredWidth(); return columnWidth; |
String | getColumnWidths(final JTable table) Returns the column widths of a table in a formatted String . Objects.requireNonNull(table); TableColumnModel model = table.getColumnModel(); int count = model.getColumnCount(); StringBuilder buffer = new StringBuilder(); for (int i = 0; i < count; i++) { if (i > 0) { buffer.append(' '); int index = table.convertColumnIndexToView(i); buffer.append(model.getColumn(index).getWidth()); return buffer.toString(); |
int[] | getColumnWidths(JTable p_Table) get Column Widths TableColumnModel model = p_Table.getTableHeader().getColumnModel(); int[] columnWidths = new int[model.getColumnCount()]; for (int i = 0, c = columnWidths.length; i < c; i++) { columnWidths[i] = model.getColumn(i).getWidth(); return columnWidths; |
List | getColumnWidths(JTable tbl) get Column Widths final List<Integer> result = new ArrayList<Integer>(); final Enumeration<TableColumn> enumeration = tbl.getColumnModel().getColumns(); while (enumeration.hasMoreElements()) { final TableColumn column = enumeration.nextElement(); result.add(column.getWidth()); return result; |
int | getPreferredColumnWidth(JTable table, int vColIndex, int margin) get Preferred Column Width int width = 0; if (vColIndex >= table.getColumnCount()) { return 0; DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel(); TableColumn col = colModel.getColumn(vColIndex); TableCellRenderer renderer = col.getHeaderRenderer(); if (renderer == null) { ... |
int | getPreferredColumnWidth(JTable table, TableColumn col) get Preferred Column Width return Math.max(getPreferredColumnHeaderWidth(table, col), getWidestCellInColumn(table, col));
|
int | getPreferredHeaderWidth(JTable tbl, int iColumn) calculates the preferred header width by asking the header renderer. TableColumn column = tbl.getColumnModel().getColumn(iColumn); TableCellRenderer renderer = column.getHeaderRenderer(); if (renderer == null) { renderer = tbl.getTableHeader().getDefaultRenderer(); final Component compHeader = renderer.getTableCellRendererComponent(tbl, column.getHeaderValue(), false, false, 0, iColumn); int result = compHeader.getPreferredSize().width; ... |