1

I want to add a color-indicator to my JFrame. It should be turned to be red when I click a button and if I do not click a button it should be green. How should I implement this?

LionC
  • 3,106
  • 1
  • 22
  • 31
RSF
  • 41
  • 1
  • 6
  • in JFrame's content, you can add a JLabel, do you want to add at the top of the JFrame, at decoration ? - near the minimize and maximize buttons? –  Apr 25 '13 at 12:57
  • do you want it in the header? What do you want as an indicator? be more specific – Oliver Watkins Apr 25 '13 at 13:04
  • I want it to be in any place in the jframe and very small it can be circular. – RSF Apr 25 '13 at 13:14

1 Answers1

8
JLabel lblLed = new JLabel("•");
lblLed.setForeground(Color.Green);

Add an ChangeListener to your JButton and in the StateChanged() method add this:

if (buttonIsPressed) {
    lblLed.setForeground(Color.Red);
} else {
    lblLed.setForeground(Color.Green);
}
DeadlyJesus
  • 1,503
  • 2
  • 12
  • 26