kohinoor2007
Programmer
Hi all,
Have a table in which,I want to render a cell(change background color) upon double mouse click,on that particular cell.Is that possible?.
Did try something as follows:
//Have enabled row selection.I need that & no cell selection
table.setColumnSelectionAllowed(false);
table.setRowSelectionAllowed(true);
table.addMouseListener(new TableCellSelectionAdapter());
Also wrote an adapter class.
class TableCellSelectionAdapter extends MouseAdapter{
public void mouseClicked(MouseEvent e){
int selectedRow = this.table.getSelectedRow();
int selectedCol = this.table.getSelectedColumn();
int clickCount = e.getClickCount();
if(selectedRow!=0 && selectedCol!=0 && clickCount ==2) //Row=0 for headerRow,Col =0 for forst col.
{
TableCellRenderer cellRenderer = ReprintAssemblyView.this.table.getCellRenderer(selectedRow,selectedCol);
Component comp = cellRenderer.getTableCellRendererComponent(this.table, this.table.getValueAt(selectedRow,selectedCol),true ,true,selectedRow,selectedCol);
comp.setBackground(Color.green);
}
}
}
Now the above piece of code changes the background color of the whole row of the cell, on which I have double clicked,and Iam able to see the color change in my double clicked row only after I change the selection to some other row(Not instantly).
Know this is because iam using the default cell renderer.
Instead of the whole row & all the cells background color, being getting changed,want only the double clicked cell to change background color.
Any ideas....
Thanks