I have a JTable with (6) columns in it, the 1st column is a (CheckBox) field. When a user checks a checkBox of those, i want to make the backColor of the row of this checkBox=(Red) + the color of another specific row=(Blue).
I succeeded to change the color of the first row to (Red), because it's the current row i'm standing on, but how to change the color of another specific row ??
I think a renderer can render the column or cell i'm standing on right now only.
Thanks for reply Sven. I already tried this solution before but it didn't work. I don't know why it's not working but i think because the renderer can only change the color of the focused row. I even did another solution to check it :
After changing the color of the first row, i forced selecting row(13) and tried to change its color to (Blue), it did change its color to (Blue) but also returned back the color of the first row to (Black) ... Strange.
Here is my code : 1. Event to check if a checkBox is checked :
2. Here's my renderer class :
The behavior of the renderer is really strange, it can render the whole column or only (1) cell i'm standing on right now. Any Suggestions ? [ August 14, 2008: Message edited by: Hesham Gneady ]
I see here you created a table, filled it with data, then assigned a renderer to its columns. Now when the user selects a row & its first cell's value is (1) then the renderer should render all this row cells to make their backColor 'RED', right ?
Now what happens when you select another row ? Does it keep the previous selected row's color (RED) and makes the new selected row's color (RED) too ? (Because i see my code is very similar to yours but this didn't happen to me, what happens to me is that it will update the new selected row color & resets the color of the previous selected one).
I've found a nice solution that will do the trick, a method called prepareRenderer() for the JTable, this method is responsible for rendering each cell in the JTable. By overriding this method i can control the styling for each cell.
This works but only if I do repaint on the frame.
It colors the rows one at a time every second.
However in netbeans I am only seeing the last result(last cell coloured).
I can't do a repaint on the frame I think in netbeans.
I am pretty close can some one nudgwe me to the finish line?