About ColumnInfo
I am working with tables, specifically TableView, ListTableModel and ColumnInfo. I love the way these things work together.
Assume I have an Issue class with some String properties and a Date property.
I have some questions about ColumnInfo though:
- Should valueOf() *always* return a String or should it return the original object, for example the Date, and let the TableCellRenderer handle the conversion to String?
- How do I implement a renderer that uses a property of the original Issue object? Because if I have a ColumnInfo<Issue, Date> (Where Issue is my own class containing a Date), then the value that public TableCellRenderer getRenderer(Item) gets is a Date and not an Issue.
I hope this makes sense.
Cheers!
Please sign in to leave a comment.
If ColumnInfo<Item, Aspect> is defined then:
1. valueOf() should always be of type Aspect and
the result of valueOf() goes to TableCellRenderer.getTableCellRendererComponent call as value
2. If you need more than one item aspect to render a cell several options are available:
1. Setup renderer in getRenderer(Item) method as it receives Item (and not Aspect) as parameter
2. Override getCustomizedRenderer(Item, renderer) and perform additional renderer configuration there
3. Use ColumnInfo<Item, Item> approach and provide renderer that knows how to extract and present some specific Aspect
options 1 and 2 are easier when renderer instance is an actual JComponent as it happens with DefaultTableCellRenderer (inherits JLabel)