Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jtable change cell value effect  RSS feed

 
Pham Duy Hung
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with jtable, i wanna build a jtable, when i change cell value (using setValueAt() or any way), background color of this cell will be changed to a specified color (ex: Color.RED), after 500ms, it will be changed to default background color (ex: Color.BLACK), i'm using thread, but it can not resolve my problem, here's my sample code:

Thank in advance..

 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A renderer is shared by all cells in column so its values are always reset to the defaults before the cell is painted. So every time the cell is repainted the background will be reset to red. So what you really need is a method in your renderer that indicates if the cell should be painted in its default color or the blinking color. You would turn this on when you need it to blink and then each blink should turn it off.

Also, table.repaint() is not the way to do this. This will cause all the cells to be repainted. You should use the AbstractTableModel.fireTableCellUpdate(...) to invoke repainting of a specific cell.
 
Pham Duy Hung
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:A renderer is shared by all cells in column so its values are always reset to the defaults before the cell is painted. So every time the cell is repainted the background will be reset to red. So what you really need is a method in your renderer that indicates if the cell should be painted in its default color or the blinking color. You would turn this on when you need it to blink and then each blink should turn it off.

Also, table.repaint() is not the way to do this. This will cause all the cells to be repainted. You should use the AbstractTableModel.fireTableCellUpdate(...) to invoke repainting of a specific cell.


Thank for your help, i'll try, but in this case, i change bgcolor in setValue() method, so i can not pass 2 agr row and column to AbstractTableModel.fireTableCellUpdate(...) (where can i take it), can you show me an example, thank very much.
 
Rob Camick
Ranch Hand
Posts: 2756
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a complicated example. Maybe you can figure out how to customize it for your specific purpose:


 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!