JTable - Can I change the color of the text on a row by row basis?

Hi All,

I'm redoing a bit of old uni coursework (to model a stockmarket, stock ticker server & stock ticker application) to brush up my Java skills (esp Swing and Event Handling) and am programming the UI by hand using Swing (its the only way to learn something....(I've certianly nailed Layout Management!!))

In the stocktickerserver GUI I'm using a JTable to display the details about stocks.

The user can select a stock and view the details of the stock in another frame. In one panel in the JFrame I've got a JTable listing the history items for the stock (Price, Change, Date).

Is it possible to color the rows of the JTable according to the value of the change column (or at least the value I insert there)?

e.g

if (change > 0){

Blue;

else{

if (change < 0){

Red;

}

else{

Green;

}

I'm completly ignorant on how to achieve this (or even if its possible at all) so all your ideas welcome.

Any help much appreciated

Pete

P.S.

The Stock History is a class that I store in a [private] Vector in the Stock Class.

For the selected Stock I loop through this vector getting the items (using various accessor methods)

I extract the values from the return StockHistory object and build a DefaultTableModel from these

Then I call JTable.setModel(theModel) to build the table

[1426 byte] By [petergoodruma] at [2007-9-29 21:30:38]
# 1
implement TableCellRenderer and change foreground of the Renderer in the method getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) . Install this renderer to your table.
jjj110200a at 2007-7-16 1:48:46 > top of Java-index,Archived Forums,Swing...
# 2
This article explains what a renderer is and gives some examples: http://www-106.ibm.com/developerworks/java/library/j-jtable/index.html?dwzone=java
camickra at 2007-7-16 1:48:46 > top of Java-index,Archived Forums,Swing...