I would like to match color search results text with the checkbox text after clicking search button. See pic.
Currently I can view the Search Results text color but it doesn't match the checkbox text color after clicking search button. The code below is only for the Search Car Results text area and a class named CarBrand that matches the key of this HashMap carDetails. I am not sure how to compare and match its color using HashMap. Any suggestions would be great!
import java.awt.Color;
import java.swing.tree.DefaultTreeCellRenderer
public final class CarDetails extends DefaultTreeCellRenderer
{
private final Color defaultColor;
private final HashMap<String, Color> carDetails = new HashMap<>();
public CarDetails()
{
int i = 0;
defaultColor = getBackground(); //default color
int [][] rgb = {
{ 200, 000, 200 },
{ 000, 140, 000 },
{ 000, 200, 200 }
};
for (CarBrand car: CarModel.getCarBrandDetails()) {
carDetails.put(car.getCarBrand(), new Color(
rgb[i][0], rgb[i][1], rgb[i][2]));
i++;
// TODO this part is what I am not sure.
if (carDetails.containsKey(car.getCarBrand()) && carTable != null) {
for (Component c : carTable.getComponents()) {
if (c.getName().equals(car.getCarBrand())) {
c.setForeground(carDetails.containsObject(new
Color(rgb[i][0], rgb[i][1], rgb[i][2])));
}
}
}
}
}
}
I expect the output to match the color coding of the Search Car Results with the CheckBox text (Honda, Hundai, BMW) like the pic below.