Wednesday, August 7, 2013

Java: prepareRenderer, TableCellRenderer.. How to use this sub class?

Java: prepareRenderer, TableCellRenderer.. How to use this sub class?

Firstly I am new to Java and so I try to solve my problem. I would like to
change background color of current cell in different color. So I used
following codes. But I could not understand where is the problem?
mytable.prepareRenderer(new TableCellRenderer(){
@Override
public Component getTableCellRendererComponent(JTable
table, Object value, boolean isSelected, boolean
hasFocus, int row, int column) {
Component c = table.getComponentAt(row, column);
c.setBackground(Color.red);
return c;
}
}, mytable.getSelectedRow(), mytable.getSelectedColumn());
Besides I would like to know how to implement subclass TableCellEditor to
specific cell according to above fashion. Can anybody help me?

No comments:

Post a Comment