重用 TableCellEditor 对象
所以我有很多表格和很多单元格编辑器,里面有很多东西。 我想我应该重用它们,而不是每次都执行 new() ,因为整个事情都设置了 getTableCellEditorComponent() 但仍然,几乎每次我尝试这样做时,我都会在旧单元格中得到“剩余物”,以及其他奇怪的情况。 我通常可以通过每次重新制作一个新的来解决问题,但这很糟糕吗?
谢谢! 约书亚
So I have lots of tables and lots of cell editors, with lots of stuff in them. I figured I should be reusing them, not doing new() every time since the whole thing is set getTableCellEditorComponent() but still, nearly every time I try to do it, I get "leftovers" in old cells, and other oddities. I can usually correct the problem by just making a new one every time, but is this bad?
Thanks!
Joshua
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JTable
非常庞大。 虽然TableCellEditor
中的JComponent
子类也可能相当大,但并不值得担心。 此外,最好避免共享可变对象,尤其是像 Swing 组件这样复杂的对象。 每个组件生命周期有一个父组件似乎是一个不错的选择。JTable
s are huge. While theJComponent
subclass in aTableCellEditor
may also be quite large, it isn't really worth worrying about. Further, it is a good idea to avoid sharing mutable objects, particularly ones as complicated as Swing components. Having one parent per component lifetime seems a good option.由于每个
JTable
始终有零个或一个编辑器,因此getTableCellEditorComponent()
调用的性能并不是非常关键。 不过,在处理表渲染器时必须避免创建新组件。Since there is always zero or one editor per
JTable
, the performance of thegetTableCellEditorComponent()
call is not extremely critical. Creating new components must be avoided when dealing with the table renderer, though.