定制jTable
我需要定制我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅如何使用表格,概念:编辑器和 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 usesetDefaultRenderer
to associate your class with your renderer, as shown in this example.您必须使用 ListCellRenderer 为此,
此处阅读类似的问题。
You have to make use of a ListCellRenderer for this,
Read a similar question here.
您可以访问此网页,它非常有帮助
you can visit this webpage it's reeeeeeally helpful