JTable - 在多个单元格中换行文本

发布于 2024-09-12 04:01:12 字数 470 浏览 0 评论 0原文

我知道如何实现包装单元格渲染器,但是当您有多个包装列时,所有流行的实现都会中断。他们根据需要设置行高,但这样一列可以覆盖另一列的设置。通常,事实上是最后一列决定行高。

例如,对于此数据:

| 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2024-09-19 04:01:12

我自己解决了。我记住了地图中各个单元格的高度,并在每次渲染单元格时计算行最大值。

Resolved it myself. I memoized individual cell heights in a map and calculated row maximum each time a cell was rendered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文