Search code examples
javaswingjtablerowpreferredsize

Calculating dimensions of a cell in a JTable


How can I calculate the dimenstions of the cell in JTable containing various components to calculate the height of table dynamically.

For example, I have a table containing multiple checkboxes in the 3rd column and various components in other columns. When new components are added to the cell, then the height and width of the whole table should change dynamically.

Thanks in advance.


Solution

  • You might be able to leverage the approach shown here, which invokes setRowHeight() to accommodate the maximal height of each column's renderer.

    image