JTable - 在多个单元格中换行文本
我知道如何实现包装单元格渲染器,但是当您有多个包装列时,所有流行的实现都会中断。他们根据需要设置行高,但这样一列可以覆盖另一列的设置。通常,事实上是最后一列决定行高。
例如,对于此数据:
| Fairly lengthy text | Shorter Text |
如果缩小第二列,您会得到:
| Fairly lengthy text | Shorter |
| | Text |
没什么问题,但是如果缩小第一列,您可能会得到:
| Fairly lengthy | Shorter Text |
第二行不会显示,因为“较短的文本”覆盖了首选高度。
如何在不创建交叉引用和堆栈溢出的情况下实现此目的?您知道任何现成的实现吗?
I know how to implement a wrapping cell renderer, but all popular implementations break when you have multiple wrapping columns. They set row height on demand, but this way one column can override another one's settings. Usually it's de facto the last column what determines row height.
E.g. for this data:
| Fairly lengthy text | Shorter Text |
If you shrink the second column you get:
| Fairly lengthy text | Shorter |
| | Text |
What is just fine, but if you shrunk the first column, you could get:
| Fairly lengthy | Shorter Text |
Second row is not displayed because "Shorter Text" overrode preferred height.
How can I implement this without creating cross-references and stack overflow? Do you know any ready-to-use implementations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己解决了。我记住了地图中各个单元格的高度,并在每次渲染单元格时计算行最大值。
Resolved it myself. I memoized individual cell heights in a map and calculated row maximum each time a cell was rendered.