• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

jtable change cell value effect

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a complicated example. Maybe you can figure out how to customize it for your specific purpose:


 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic