我有一个包含两列的表:属性和值!属性是一个枚举。现在我为枚举类设置了一个单元格渲染器(应该以小写形式显示)。
问题是:表永远不会调用渲染器!
枚举(只是一个例子):
public enum Attribute {
BLUE,BLACK,RED;
}
单元格渲染器:
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());