how to hieghlight ant row on its value change
hi all,
i am making an application in which the rows of jtable are getting updated from live data coming from forex market my problem is that i wanst to make the row highlight as soon as the data changes and goes back to normal condition after few minutes plz sujjest me.
thanks in advance
[307 byte] By [
martin1] at [2007-11-20 8:58:02]

# 1 Re: how to hieghlight ant row on its value change
The TableModel sends out TableModelEvents to any TableModelListeners when the data changes. The JTable itself is a TableModelListener, and has a tableChanged(..) method that is called when the data changes. If you have subclassed JTable, you can override this method to handle those events. If you have subclassed DefaultTableModel, you can override the relevant notification methods in that class. If you haven't subclassed JTable or DefaultTableModel, you can add your own TableModelListener to the TableModel by calling JTable.getModel() and then adding your TableModelListener to the model. This listener should check the listener event and store the row index of the row that has been updated.
To highlight the row that has changed, you need to set up the TableCellRenderer used to paint the cell contents so that it will change the colors of the display component. Because each column can have a different data type, each column has its own cell renderer. If you are using the DefaultTableCellRenderer (i.e. you haven't provided your own), you can subclass DefaultTableCellRenderer and override getTableCellRendererComponent(..) to call the superclass version, then check the row being rendered against the row stored by your custom TableModelListener. If they match, set the foreground and/or background color of the component before returning it. Set the DefaultTableCellRenderer for every table column via JTable.setDefaultCellRenderer(..) - you can use the same renderer for every one.
If you want to reset the row color after a set time, you'll need to store an entry for every row in a list (an ArrayList?). You could use a boolean value where 'true' means 'highlight this row'. Instead of your TableModelListener storing the index of the row that changes, it can set the boolean value at that index in the list to 'true'. Each time it does this, it should create and start a timer that resets the boolean value at that index, and calls repaint() on the table.
If you have a very large number of rows, you might need to get clever with the timing to avoid hundreds of timers running - e.g. store the update time in the row list and use a single repeating timer that checks the time difference at regular intervals to see if any rows need resetting.
If I had eight hours to chop down a tree, I would spend 6 hours sharpening an axe...
Anon.
dlorde at 2007-11-10 2:15:15 >
