Dislpaying Rows of Jtable with Different colors
hi
my problem is to match rows of two tables table1 and table2
if a row1 of table1 is same as that of row1 in table 2 then background colour of rows should be green
and if they are different then background colour of rows should be red
and if row1 is not present in table2 then its background colour should be yellow
For this
i matched the two rows and set add rows acc in both table and also i am taking a string variable which will have value either "same", "different" , or "new"
and to display different colors
i m using getTableCellRendererComponent
but for this i have to add "same", "different" etc in table
this is a sample code which i was using
{
TableModel jTable1Model = new DefaultTableModel(
new String[][] { { "same", "Two" },
{ "different", "Four" },{ "same", "Four" } },
new String[] { "Column 1", "Column 2" });
jTable1 = new JTable();
jScrollPane1.setViewportView(jTable1);
jTable1.setModel(jTable1Model);
String val = "same";
jTable1.setDefaultRenderer(Object.class, this);
public Component getTableCellRendererComponent(JTable table, Object value, boolean select, boolean focus, int row, int col) {
Component renderer = DEFAULT_RENDERER.getTableCellRendererComponent(table, value,select, focus, row, col);
if(value.toString().equals("same")){
renderer.setBackground(Color.green);
}
if(value.toString().equals("different")){
renderer.setBackground(Color.red);
}
if(value.toString().equals("new")){
renderer.setBackground(Color.yellow);
}
return renderer;
}
but the problem in this is that this value should be in a col of a table
then only it give me desired result
but i dont want this value to be displayed in table
so i tried to hide this column by setting width zero etc , nd even removing from columnModel but then also didnt get the result
So please help me out thanks

