Changing the background color of a table cell
Hi all,
Want to change the background colour of a specific cell when the user double clicks on the cell.
I extended the table so that it returns the "specialrenderer" for this particular cell(see code).
Also assumed that on double clicking on a cell,that will become the currently selected cell on the table.
But the cell background colour is not changing.Guess the tables "getCellRenderer" method is not getting called.
What should be done to the table ,so that it redraws the doubleclicked cell...
My requirement is when the user doubleclicks on a cell with a mouse,the cells background colour changes.When he doubleclicks on a different cell,the current cells background colour is changed & the old selection(doubleclicked cell) goes to the default colour.
Thanks....
publicclass ReprintTableextends JTable{
private DefaultTableCellRenderer specialRenderer;
public ReprintTable()
{
super();
}
public ReprintTable(TableModel tm){
super(tm);
}
public ReprintTable(Object[][] data, Object[] columns)
{
super (data, columns);
}
public ReprintTable(int rows,int columns)
{
super (rows, columns);
}
public TableCellRenderer getCellRenderer(int row,int column){
int selectedRow = this.getSelectedRow();
int selectedCol = this.getSelectedColumn();
if ((selectedRow == row) && (selectedCol ==column))
{
specialRenderer =new DefaultTableCellRenderer();
specialRenderer.setBackground(Color.green);
return specialRenderer;
}
else
return super.getCellRenderer(row, column);
}
}

