Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Change JTable's row background dynamically  RSS feed

 
Mehul Mistry
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I need to do tricky stuff but totally lost on how and where to start. I have a JTable in my application to which I'll be adding some rows dynamically based on some events. I have used my own table model class (which extends DefaultTableModel) and also implemented a TableCellRenderer to construct the table.
Now I need to change the background colors of some rows based on some caluclated time events. To be more clear about this, once the rows are added, after sometime I need to change the color of few rows, based on some countdown timer.The color will keep on changing, as the countdown timer nears to a deadline time.
What I am planning to do is, have a seperate class to run a thread for countdown time. I'll also try to get the Jtable and the table model objects to that class. But once a certain time occurs, how do I change the colour of one particular row, and that too outside of the class contructing the table. I don't know how do I get hold of the rows I need to change the color.
Any inputs and advice will be very very helpful.

Thanks,
Mehul
 
Mehul Mistry
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I solved this trick. I created a singleton class, which will register the object of my custom TableModel, I used to create the table.Also in this class I kept one method changeColor() which fires fireTableDataChanged(). My timer thread would be using this class at particular events and calls the changeColor() method.
As this is done, my table is repainted and in my TableCellRenderer I implemented the logic to change the color of the rows which I wanted. Again, which color to change and at a particular time was maintained at common place.

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