JTable color row, based on info outside the table

Hi everybody,

I have an object called "Event" which I visualize in a JTable. I create the Object[][] data array for the JTable like this:

// Convert the events to table data.

Object data[][] =new Object[p_events.size()][6];

int i = 0;

for (Event event : p_events)

{

if (event.hasSubject()) data[i][0] = Library.replaceNSforPrefix(event.getSubjectURI());

data[i][1] = Library.replaceNSforPrefix(p_relationURI);

if (event.hasObject()) data[i][2] = Library.replaceNSforPrefix(event.getObjectURI());

data[i][3] = event.isPartial();

data[i][4] = event.isValid();

data[i][5] = event.numberOfNewsItems();

++i;

}

I pass this array to my table model in order to create a model which is used for the JTable. Now I have the following problem: I want to color a row red based on a certain attribute of the Event object of that respective row. However, that attribute is not visualized in the table. How can I best go about doing such a thing?

Best regards,

Jethro

[1309 byte] By [Jethroa] at [2007-11-27 2:36:10]
# 1

> However, that attribute is not visualized in the table

Well, add that attribute to the TableModel. Then remove the TableColumn from the TableColumnManager so the column is not displayed in the table. Now when you go to render the table you can test the value of the attribute to determine the color of the row as is demonstrated in this posting:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

camickra at 2007-7-12 2:55:10 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you very much, I override the prepareRenderer() method and everything works fine now.
Jethroa at 2007-7-12 2:55:11 > top of Java-index,Desktop,Core GUI APIs...