1 Attachment(s)
Whats wrong with this row in jtable?
y dosent this row get the color ??
Attachment 2007
Code :
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer()
{
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column);
Boolean last=(Boolean)table.getValueAt(row, 3);
if(Boolean.TRUE.equals(last))
{
c.setBackground(Color.green);
table.repaint();
} else {
c.setBackground(Color.red);
table.repaint();
}
return c;
}
});
Re: Whats wrong with this row in jtable?
Please post code in the form of an SSCCE. Also, please use proper English, as many of our users are not native English speakers, and using "y" instead of "why" can be confusing.
But here's a guess: the Component returned from the call to super.getTableCellRendererComponent() is in fact a JLabel. By default, JLabels are not opaque, which means their backgrounds are not painted. You can call the setOpaque() method on your c variable, but you'll have to cast it first.
Re: Whats wrong with this row in jtable?