简体   繁体   English

如何实现具有可变行高的jtable

[英]How to implement jtable with variable row-height

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. 我有一个多列jtable,我希望根据字符串中的换行符(“\\ n”)在单元格中的多行显示某些列的字符串内容。 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 TIA

If I got you right, I think you need a MultilineCellRenderer . 如果我找对你,我认为你需要一个MultilineCellRenderer。 There are already plenty of examples around. 已经有很多例子了。 Normally they are based on a JTextArea to get the line wrap functionality. 通常它们基于JTextArea来获取换行功能。

I haven't used it myself yet, but here is an example, which looks kinda good at first view: 我还没有用过它,但是这里有一个例子,看起来有点擅长第一个视图:

MultilineCellRenderer MultilineCellRenderer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM