0

I have a JTable where each cell occupy the same amount of space, but somethimes happen that text doesn't fit well inside cell, so i can't read entire content. There's a way to adapt each table row height for show correctly all its content? So each table row could have different height, and the maximum heigth o row is the minimum height to contain thew most long text

giozh
  • 9,868
  • 30
  • 102
  • 183
  • 2
    http://blog.botunge.dk/post/2009/10/09/JTable-multiline-cell-renderer.aspx and http://stackoverflow.com/questions/965023/how-to-wrap-lines-in-a-jtable-cell – StanislavL Jan 14 '15 at 14:01
  • 1
    See `TextAreaRenderer` presented [here](http://stackoverflow.com/a/20339015/1795530) that uses a `JTextArea` with line wrap active in order to achieve what you want. – dic19 Jan 14 '15 at 14:03

1 Answers1

1

You can set the row height individually. When any value is changed, call this code:

int height = table.getRowHeight(row);
int newHeight  = table.prepareRenderer(table.getCellRenderer(row, column), row, column).getPreferredSize().height;
if (newHeight > height) {
    height = newHeight;
}
table.setRowHeight(row, rowHeight);
Jean Waghetti
  • 4,711
  • 1
  • 18
  • 28