List of utility methods to do JTable Row Height
void | correctRowHeight(JTable table) Update table row height to the best possible considering font size changes on the current platform http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4760081 FontMetrics metrics = table.getFontMetrics(table.getFont()); table.setRowHeight(Math.max(table.getRowHeight(), metrics.getHeight())); |
int | getPreferredRowHeight(JTable table, int rowIndex, int margin) get Preferred Row Height int height = table.getRowHeight(); for (int c = 0; c < table.getColumnCount(); c++) { TableCellRenderer renderer = table.getCellRenderer(rowIndex, c); Component comp = table.prepareRenderer(renderer, rowIndex, c); int h = comp.getPreferredSize().height + 2 * margin; height = Math.max(height, h); return height; ... |
Rectangle | getRowBounds(JTable table, int row, int height) Get bounds for row +/- height rows. int first = Math.max(0, row - height); int last = Math.min(table.getRowCount() - 1, row + height); Rectangle result = table.getCellRect(first, -1, true); result = result.union(table.getCellRect(last, -1, true)); Insets i = table.getInsets(); result.x = i.left; result.width = table.getWidth() - i.left - i.right; return result; ... |
void | packRowHeights(final JTable table) Packs all table rows to their preferred height. for (int row = 0; row < table.getRowCount(); row++) { int maxHeight = 0; for (int column = 0; column < table.getColumnCount(); column++) { final TableCellRenderer cellRenderer = table.getCellRenderer(row, column); final Object valueAt = table.getValueAt(row, column); final Component renderer = cellRenderer.getTableCellRendererComponent(table, valueAt, false, false, row, column); final int heightPreferable = renderer != null ? renderer.getPreferredSize().height : 0; ... |
void | platformTableRowHeight(JTable jtab, boolean forEdit) Use to set table rows (platform-dependent) boolean isAMac = System.getProperty("os.name").toLowerCase().startsWith("mac os x"); if (isAMac) { if (forEdit) { if (macHeight_ == 0) { Vector condTypes = new Vector(); condTypes.add("XXXjjggTT"); JComboBox testIt = new JComboBox(condTypes); macHeight_ = testIt.getPreferredSize().height; ... |
void | setRowHeight(JTable table, int row) set Row Height table.setRowHeight(row); |
void | updateRowHeights(JTable table) update Row Heights for (int row = 0; row < table.getRowCount(); row++) { int rowHeight = table.getRowHeight(); for (int column = 0; column < table.getColumnCount(); column++) { Component comp = table.prepareRenderer(table.getCellRenderer(row, column), row, column); rowHeight = Math.max(rowHeight, comp.getPreferredSize().height); table.setRowHeight(row, rowHeight); |