Forums Register Login

modifying default renderer for Boolean class

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 773 times.
Similar Threads
Adding checkbox to some selected row of a column.
getTableCellRendererComponent() in Jtable-doubt(urgent please)
Make String display bold or italic
JTable - JDBC - Vectors
Cannot uncheck JCheckBox in JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:21:22.