У меня есть таблица с двумя столбцами: атрибут и значение!
Атрибут является перечислением. Теперь я установил средство визуализации ячеек для класса enum (должно отображаться в нижнем регистре).
Проблема в том, что таблица никогда не вызывает рендерер!
Enum (только пример):
public enum Attribute {
BLUE,BLACK,RED;
}
Cell Renderer:
public class AttributeTableCellRenderer
extends
AbstractTableCellRenderer<Attribute> {
@Override
protected Object getText(Attribute attribute) {
System.out.println("call");
if (null == attribute) {
return null;
}
return attribute.toLowerCase();
}
}
Таблица (только пример):
// table model
Vector<Object> v;
Vector<String> header = new Vector<String>(Arrays.asList("attribute", "values"));
Vector<Vector<?>> data = new Vector<Vector<?>>();
// fill with data
for (final Attribute attribute : Attribute.values()) {
v = new Vector<Object>();
v.add(attribute);
v.add("blah");
data.add(v);
}
//table
TableModel tm = new DefaultTableModel(data, header);
JTable table = new JTable(tm);
table.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
table.setDefaultRenderer(Attribute.class, new AttributeTableCellRenderer());
// will work
//table.setDefaultRenderer(Object.class, new AttributeTableCellRenderer());