How to implement jtable with variable row-height
Asked Answered
B

1

11

None of the answers to two previous questions (here and here) resolve my problem.

I have a multi-column jtable for which I want to display string-content of some columns over more than one line within the cell based on newline char's ("\n") within the string. The number of newlines per string is random, known only at run-time. Only the affected row must be adjusted across all columns to the new height. There may be a different number of lines per affected column, and the row-height needs to be adjusted to the maximum height of these, across the columns.

How do I do this?
If possible some sample code would be very much appreciated.
TIA

Byars answered 17/9, 2010 at 8:17 Comment(0)
O
13

If I got you right, I think you need a MultilineCellRenderer . There are already plenty of examples around. Normally they are based on a JTextArea to get the line wrap functionality.

I haven't used it myself yet, but here is an example, which looks kinda good at first view:

MultilineCellRenderer

Oxidation answered 17/9, 2010 at 8:28 Comment(3)
Thank you! - this works like a charm. I must become a member just so I can upvote you!Byars
Glad I could help. And indeed, you have to (become a member)! StackOverflow is worth it ;)Oxidation
Thanks from me, too. I had to change this class a bit so it could be used together with other TableCellRenderers in one JTable, but this was minor.Trial

© 2022 - 2024 — McMap. All rights reserved.