定制jTable

发布于 2024-08-25 12:07:48 字数 300 浏览 2 评论 0原文

我需要定制我的 jTable。我所需要的只是将自定义 Swing 对象(如 jButon、jPanel 等)放入表格单元格中。是否可以?我正在尝试:

jTable.getModel.setValueAt(jPanel1,0,0)

jTable.getModel.setValueAt(jPanel1.getUI(),0,0)

结果只是某种字符串,代表对象...

我知道自定义渲染器,但仍然没有掌握正确注册它们的技术。你怎么做到的?

I need to customize my jTable. All I need, is to put a custom Swing object (like jButon, jPanel, etc.) into the table cell. Is it possible? I'm trying:

jTable.getModel.setValueAt(jPanel1,0,0)

and

jTable.getModel.setValueAt(jPanel1.getUI(),0,0)

But the result is only a some kind of string, representing the object...

I'm aware of custom renderers, but still don't get the technique of registering them properly. How do you do that?

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

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

发布评论

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

评论(3

秋叶绚丽 2024-09-01 12:07:49

请参阅如何使用表格,概念:编辑器和 Swing 教程中的渲染器。听起来您正在获取 Object 的默认渲染器,它“由显示对象字符串值的标签渲染”。您可以使用 setDefaultRenderer 将您的类与渲染器关联起来,如此示例

See How to Use Tables, Concepts: Editors and Renderers in the swing tutorial. It sounds like you're getting the default renderer for Object, which is "rendered by a label that displays the object's string value." You can use setDefaultRenderer to associate your class with your renderer, as shown in this example.

笔芯 2024-09-01 12:07:49

您必须使用 ListCellRenderer 为此,
此处阅读类似的问题。

You have to make use of a ListCellRenderer for this,
Read a similar question here.

久伴你 2024-09-01 12:07:49

您可以访问此网页,它非常有帮助

you can visit this webpage it's reeeeeeally helpful

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