how to grayout non editable cell in JTable
853982May 6 2011 — edited May 6 2011hi
I am developing a jtable application, I have some cells with null values. I have set those cells in non editable mode. Now I am trying to set gray background color of those cells.
I have used following code but It sets all cells (Editable also) in gray color.
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (!isCellEditable(row, column)) {
c.setBackground(Color.GRAY);
}
return c;
}
};
When I add the else part in condotion.like this
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component c = super.prepareRenderer(renderer, row, column);
if (!isCellEditable(row, column)) {
c.setBackground(Color.GRAY);
}
else{
c.setBackground(Color.white);
}
return c;
}
};
then it sets the color properly but it does not highlight all cell text when I select it. and text also not visible in nimbus, windows and CDE/Motif look and feel.(because I set the background color is white).
Your assistance will be appreciated
Thanks