I cant find the answer to this anywhere – i am sure it is really simple but im quite confused!
i want to change the colour of the cell background when the value changes.
I have written a cell renderer below:
public class CyanTableCellRenderer extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
cell.setBackground( Color.CYAN );
return cell;
}
}
I want to pass the value of the cell from the event in the listener – to highlight the cell.
Can anyone help?
As suggested by @mKorbel,
prepareRenderer()can apply changes to any selected renderer. Alternatively, you can condition the color based on theisSelectedparameter of your renderer.If you just want to change the default background color for selected cells, alter the
UIManagerpropertyTable.selectionBackgroundearly in your program. This will affect all tables during execution.