Java examples for Swing:JTable Row
Returns the JTable preferred height for the given row.
//package com.java2s; import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; public class Main { /**/*from ww w.j a v a 2 s. c om*/ * Returns the preferred height for the given row. It loops * across all visible columns and returns the maximal pref height of * the rendering component. Falls back to the table's base rowheight, i * f there are no columns or the renderers * max is zeor.<p> * * @param table the table which provides the renderers, must not be null * @param row the index of the row in view coordinates * @return the preferred row height of * @throws NullPointerException if table is null. * @throws IndexOutOfBoundsException if the row is not a valid row index */ public static int getPreferredRowHeight(JTable table, int row) { int pref = 0; for (int column = 0; column < table.getColumnCount(); column++) { TableCellRenderer renderer = table.getCellRenderer(row, column); Component comp = table.prepareRenderer(renderer, row, column); pref = Math.max(pref, comp.getPreferredSize().height); } return pref > 0 ? pref : table.getRowHeight(); } }