• Post Reply Bookmark Topic Watch Topic
  • New Topic

modifying default renderer for Boolean class

 
Nadin Jovan
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to modify the default renderer for Boolean class to disable certain JCheckBox cells in a table.
I overwrote the method getCellRenderer as follows:
public TableCellRenderer getCellRenderer(int row, int col) {
if (col == 0) return this.getDefaultRenderer(String.class);

if (!this.getModel().isCellEditable(row, col)) {
TableCellRenderer renderer = this.getDefaultRenderer(Boolean.class);
if (renderer instanceof JCheckBox) {
JCheckBox box = (JCheckBox)renderer;
box.setEnabled(false);
box.setBorderPaintedFlat(true);
//box.setForeground(Color.LIGHT_GRAY);
//box.setBackground(Color.BLUE);
}
return renderer;
}
return this.getDefaultRenderer(Boolean.class);
}
I would expect this to render all uneditable cells as disabled JCheckBoxes, but it didn't.
Any ideas what I might be doing wrong?
Thanks.
 
Tamizh Selvan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
you can try overriding the belo method.
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column);
Hope this w'd help u.
Tamizh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!