• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and animation refreshing problem

 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
David Irwin
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic