Ok, So I make a JToggleButton:
JToggleButton button = new JToggleButton(new ImageIcon(features[i].getImage())) {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
super.paint(g);
if (isSelected()) {
g.setColor(Color.RED);
g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
}
}
};
try {
if (bodyButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getBody().getImage())) {
button.setSelected(true);
}
} else if (eyesButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getEyes().getImage())) {
button.setSelected(true);
}
} else if (glassesButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getGlasses().getImage())) {
button.setSelected(true);
}
} else if (hairButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getHair().getImage())) {
button.setSelected(true);
}
} else if (pantsButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getPants().getImage())) {
button.setSelected(true);
}
} else if (shirtButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getShirt().getImage())) {
button.setSelected(true);
}
} else if (shoesButton.isSelected()) {
if (equals(features[i].getImage(), avatar.getShoes().getImage())) {
button.setSelected(true);
}
}
} catch (Exception e) {}
But I am having problems with it not painting. I setting selected true right after its institated as you can see, but its not painting the button SOMETIMES, Other times it work GREAT! Iknow that it is being set to true because I added a after it.
System.out.println(button.isSelected() + " " +i);