JTable.setRowHeight 阻止我添加更多行

发布于 2024-08-27 02:42:39 字数 349 浏览 2 评论 0原文

我正在开发一个非常简单的 Java 应用程序,以便了解有关 JTable、TableModel 和自定义单元格渲染器的更多信息。该表是一个简单的表,有 8 列,其中仅包含文本。当您单击“添加”按钮时,会弹出一个对话框,让您输入列的数据。

现在我的问题。其中一列(最后一列)应允许多行文本。我已经将 HTML 放入该字段中,但它没有换行。我做了一些研究并研究了 JTable#setRowHeight()。但是,一旦我使用 setRowHeight,我就无法再向表中添加行。数据已放入表模型中,但未显示在表中。如果我删除 setRowHeight 行,那么它会很好地添加数据。

是否还有另一个步骤可以将数据添加到我缺少的数据模型?

多谢!

I'm working on a pretty simple Java app in order to learn more about JTables, TableModels, and custom cell renderers. The table is a simple table with 8 columns only with text in them. When you click on an "add" button, a dialog pops up and lets you enter the data for the columns.

Now to my problem. One of the columns (the last one) should allow for multiple lines of text. I'm already putting HTML into the field, but it is not wrapping. I did some research and looked into JTable#setRowHeight(). However, once I use setRowHeight, I can no longer add rows to the table. The data is put into the table model, but it does not show in the table. If I remove the setRowHeight line, then it adds data just fine.

Is there another step to adding data to my data model that I'm missing?

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

与酒说心事 2024-09-03 02:42:39

您必须更换单元格编辑器。默认的单元格编辑器是 JTextField,我不认为它允许文本换行。 JTextArea 或类似的组件可以让您做到这一点。

至于 setRowHeight() 不允许您添加新行,我以前从未听说过。你能提供更多细节吗?或者至少是你使用的代码?我无法重现结果,因为尽管使用了 setRowHeight(),但我仍能够继续添加新行。

You have to replace the cell editor. The default cell editor is a JTextField, I don't believe that allows for text wrap. A JTextArea or similar component would allow you to do that.

As for setRowHeight() disallowing you from adding new rows, I've never heard that before. Can you provide more details? or at the very least the code you used? I'm not able to reproduce the results as I am able to continue to add new rows despite using setRowHeight().

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