Reputation: 1
This is employee data information. I have the contact starting date and expiration date, so I want to know how I can highlight a row in the jtable if there is a contact that will expire in one month or less.
Thank you
Upvotes: 0
Views: 256
Reputation: 324137
You can override the prepareRenderer(...)
method of Table
to highlight the entire row based on the data in the row:
JTable table = new JTable( model )
{
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
{
Component c = super.prepareRenderer(renderer, row, column);
if (!isRowSelected(row))
{
Date date = getModel().getValueAt(row, ???);
if (date expires in one month)
c.setBackground( someColor );
else
c.setBackground( getBackground() );
}
return c;
}
};
Check out Table Row Rendering for some working examples.
Upvotes: 3