wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes JTable and animation refreshing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable and animation refreshing problem" Watch "JTable and animation refreshing problem" New topic
Author

JTable and animation refreshing problem

David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
All,

I have a JTable and a custom ImageIcon class for one particular column in my table. The custom ImageIcon class is used to overlay and fade in/fade out a small additional image on the background image (think of a small recording icon that fades in and out when recording is taking place for a given row).

Everything works well except for getting the cell to update. If I move my mouse in and out of the cell then the small overlay icon updates, but if I just leave the cell alone it doesn't update.

Here's a snippet of the code that I'm using to update the custom ImageIcon:



I'm using the TimingFramework to actually do the timing. Here's a snippet from the timing target:



I currently don't call a repaint() on the actual JTable after the Alpha component has been updated. Do I need to do this? Are there any other ideas to get the small overlay icon to update automatically?

Thanks,
Dave
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by David Irwin:
I have a JTable and a custom ImageIcon class for one particular column in my table. The custom ImageIcon class is used to overlay and fade in/fade out a small additional image on the background image (think of a small recording icon that fades in and out when recording is taking place for a given row).

Everything works well except for getting the cell to update. If I move my mouse in and out of the cell then the small overlay icon updates, but if I just leave the cell alone it doesn't update.

...

I'm using the TimingFramework to actually do the timing. Here's a snippet from the timing target:



I currently don't call a repaint() on the actual JTable after the Alpha component has been updated. Do I need to do this?


You do need to force the table to actually redraw the icon, but calling
repaint() on the JTable is not the correct way to do this. What you want
to do in the timing event is have the table model call fireTableCellUpdated()
for the cell(s) in question.

Are you already extending AbstractTableModel for your table model? If so
it's probably easiest to just do all the timer stuff from within your model.



[edit: btw, ImageIcon.component.repaint() doesn't do what you think it does.
In fact, it does nothing. For one, ImageIcon.component is static and shared
by all ImageIcons. It is used only by the loadImage() method, and then only
indirectly by ImageIcon's static MediaTracker. The API probably shouldn't have
exposed it.]
[ May 27, 2008: Message edited by: Brian Cole ]

bitguru blog
David Irwin
Ranch Hand

Joined: Mar 25, 2004
Posts: 82
Thanks Brian for your response.

I did try using the JTable.fireTableCellUpdated(), however I found that this cleared the current row selection in the table which is a problem for me. While as you said it may not be 100% correct, it is working when I call the JTable.repaint() method after each timing event.

Thanks,
Dave
 
Don't get me started about those stupid light bulbs.
 
subject: JTable and animation refreshing problem
 
Similar Threads
How do I layer components on top of each other without blocking lower components?
Multiple Objects in one JTable cell
Images in a JTable
Rotating an image
Is there a way to show an image in a JTable as a thumbnail?