JTable, how to highlight cells with tooltips?

Hello all!Mine problem is descriped in the topic - I though about custom cell renderer but I dont have an Idea how to change background for many other cells in other rows and don't change background in whole columns. Any of You could help?
[254 byte] By [Ziela] at [2007-11-27 5:49:17]
# 1
What are you trying to do? Can it be explained?
Hippolytea at 2007-7-12 15:35:37 > top of Java-index,Java Essentials,New To Java...
# 2
The getTableCellRendererComponent() method that you implement for the TableCellRenderer tells you which row and column it wants a renderer for. With that you should be able to highlight or set tooltip text for any cell without the entire row or column being affected the same way.
BinaryDigita at 2007-7-12 15:35:37 > top of Java-index,Java Essentials,New To Java...
# 3

Hey thanks for replying.

With code like that:

public class yellowCellRenderer

extends DefaultTableCellRenderer

{

private int whichRow = 0;

public yellowCellRenderer(int saveToRow)

{

this.whichRow = saveToRow;

}

public Component getTableCellRendererComponent(JTable table, Object value,

boolean isSelected, boolean hasFocus, int row, int column)

{

if(this.whichRow == row){

this.setBackground(Color.YELLOW); // All columns verified were empty - set our background RED

}

return this;

}

}

and usage:

comments.add(comment);

JTable table = getMainTable();

TableColumnModel colModel = table.getColumnModel();

for(int i=0;i<comment.length;i++){

if(!Main.isStringEmpty((String)comment[i])){

TableColumn column = colModel.getColumn(i);

column.setCellRenderer(

new yellowCellRenderer(table.getRowCount()-1)

);

}

}

Every each cell in column gets yellow background... What am I doing wrong?>

Ziela at 2007-7-12 15:35:37 > top of Java-index,Java Essentials,New To Java...
# 4

Because the render object is reused for each cell in the column, you need

to comprehensively set its properties every time. Say:

if(this.whichRow == row){

this.setBackground(Color.YELLOW);

} else {

this.setBackground(table.getBackground());

}

Hippolytea at 2007-7-12 15:35:37 > top of Java-index,Java Essentials,New To Java...
# 5
Thank You - it works :)
Ziela at 2007-7-12 15:35:37 > top of Java-index,Java Essentials,New To Java...