0

i have a ComboBox named 'ComboBox_status' which have default values 'In Operation' and 'Disposed'
i want the background color to change to red when 'Disposed' is selected and green when 'In Operation' is selected.

this is the code i tried but it changes the background to red for both of them when they are selected

String age="Disposed";

        if("Disposed".equals(age)){
                  ComboBox_status.setBackground(Color.red); 
                  ComboBox_status.setForeground(Color.BLACK);
                }
                else{
                    ComboBox_status.setBackground(Color.GREEN);
                    ComboBox_status.setForeground(Color.darkGray);

                }  

i will appreciate it if anyone could help me resolve this THANK YOU.

3
Contributors
4
Replies
24
Views
4 Years
Discussion Span
Last Post by mKorbel
0

basically: what you are doing is:

if ( true ) 
  setColor(RED);
else
  setColor(BLACK);

and for some reason, you expect the else block to be executed. don't hardcode the value of age, get the value selected in your JComboBox

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.