JTable coloring rows.

I have another question.

I want to set color for the whole row

Color of row depends on two cell in this row.

These to cells keep date.

If difference between dates is less than 7 days, then row is RED

else if difference is more than 7 days then the row is Green.

If user changes values in these cells, color of row should be repainted.

I've discovered topic in Forum Archive:

http://forum.java.sun.com/thread.jspa?threadID=433486&messageID=1979974

I am trying to use this part:

public Component getTableCellRendererComponent( JTable jTable, Object value,boolean isSelected,boolean hasFocus,int row,int col)

{

super.getTableCellRendererComponent(jTable, value, isSelected,hasFocus, row, col);

if(col==0){

int val = ((Integer)value).intValue();

int valMin = ((Integer)jTable.getModel().getValueAt(row,col+1)).intValue();

int valMax = ((Integer)jTable.getModel().getValueAt(row,col+2)).intValue();

setBackground(Color.green);

if( val>valMin )

setBackground(Color.yellow);

if( val>valMax)

setBackground(Color.red);

}

returnthis;

}

But I do not understand, how can I extend DefaultTableCellRenderer on replace it with Renderer I have shown to you.

[1853 byte] By [Holoda] at [2007-11-26 21:35:53]
# 1
Hi Holod,See camickr solution for this that does not use a custom renderer, but overrides prepareRenderer of JTable instead: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474
Rodney_McKaya at 2007-7-10 3:16:43 > top of Java-index,Desktop,Core GUI APIs...
# 2

Exactly what I need!!!

Thank.

P.S.

I can't understand this fact:

You and camickr suggest easy-to-use and easy-to-understand and just-easy code examples.

But tutorials from sun.com (for example "How to use SWING"->Jtable) are complicated. They make java starter to work with AbstractTableModel, to make a subclass of it and so on.

Why do they give such difficult examples?

With your help (you, camickr and other forum members ), I've achieved better results.

I do not understand this......

Holoda at 2007-7-10 3:16:43 > top of Java-index,Desktop,Core GUI APIs...