Table Field Selection
Hello,
I'm having a hard time understanding the usage of JTable.changeSelection. I have a class that extends AbstractTableModel that has 3 columns and multiple rows. After it gets populated with data I want to draw it so I have
publicclass ATableModelextends AbstractTableModel
{
....
}
publicclass ATableRendererextends JTable
{
public ATableRenderer(ATableModel themodel)
{
setModel(themodel);
setForeground(fgcolor);
setBackground(bgcolor);
setGridColor(gcolor);
setSelectionBackground(sbgcolor);
setSelectionForeground(sfgcolor);
setCellSelectionEnabled(true);
for(int i = 0; i < themodel.getRowCount(); i++)
{
if(themodel.getRowAt(i).getValueAt(0).equals("Line 0 label"))
{
if(somefunction())
{
changeSelection(i, 0, true,false);
changeSelection(i, 1, true,false);
changeSelection(i, 2, true,false);
}
}
if(themodel.getRowAt(i).getValueAt(0).equals("Line 1 label"))
{
if(someotherfunction())
{
changeSelection(i, 0, true,false);
changeSelection(i, 1, true,false);
changeSelection(i, 2, true,false);
}
}
//etc..........
}
}
}
Well.. doesn't exactly work. What I'm trying is that if for a particular row an associated function returns true I highlight the whole row, and I can have several rows highlighted. If I have changeSelection(i, column, true, false) for some reason only the first and third columns light up for all relevant rows. If I have changeSelection(i, column, false, false) only the very last applicable cell lights up (like if there were 3 rows that ougth to light up, only the last cell of the last of those rows would). I do not understand what the fourth parameter of that function refers to, or what the "anchor" talked about by the documentation refers to.
Also, if I have setCellSelectionEnabled(true) then any user can just click any cell and make that one be selected instead of whatever my constructor did. And if I set it to false, no highlighting to selection colors happens at all. Is there a way I can make it do the highlighting the constructur instructs while prohibiting highlighting by the user?
Thanks a lot!

