I would like to highlight specific rows in a JTable whenever the contents of the a cell match with an input from the user. The following code is what I have that works thus
The renderers are "rubber stamps". That basically means that they carry there previous settings over to the next cell.
What you need to do is provide a "default" behavior
if (!isRowSelected(row) ) {
c.setBackground((hashMapcontainer
.containsKey(row)) ? Color.GREEN
: getBackground());
} else {
// Define the default background color
// Don't forget to take into the selection state
}
While I personally think that prepareRenderer in this case is probably a fair solution, you really should explore the possibly of providing a base line renderer. This is a lot of work to get right but has the advantage of been portable (if you change table implementations) as well as allowing other
people the chance to define the highlight rules of a given cell, which you've basically just gone and overridden, IMHO.
I'd also suggest taking a look at JXTable as it has in built highlighting