• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing background colour of a table cell  RSS feed

 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....


[ June 22, 2007: Message edited by: kohinoor ]
[ July 19, 2007: Message edited by: Arun Sanker ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the tables "getCellRenderer" method is not getting called
That would be easy enough to verify with a println statement inside the method.
You might try overriding the prepareRenderer method instead.
Double–clicking in a table cell starts an edit session if the table has a DefaultTableModel.
If we are certain that our table does/will not have a DefaultTableModel we could use the
double–click event without interfering with default behavior. Here's one possiblity:
 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks craig,I do have a custom table model which is extended from the default table model.(because I want to make use of some of the functionalities in the default model like moving the rows,deleting ,sorting etc)

Will modify my code,may be call the "GetCellRenderer" in my mouse event & see what happens...

As its a weekend ,dont have access to the code.Will tell the result on monday...

Thanks once again...
 
Arun Sanker
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Craig, It worked...
Thanks Once again.That was Nice....
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!