views:

96

answers:

2

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

+1  A: 

JTables are huge. While the JComponent subclass in a TableCellEditor 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.

Tom Hawtin - tackline
+1  A: 

Since there is always zero or one editor per JTable, the performance of the getTableCellEditorComponent() call is not extremely critical. Creating new components must be avoided when dealing with the table renderer, though.

morsch