vijay
vijay

Reputation: 1139

Set selected Text to JComboBox

Sample code:

yesNoBoxRem.addActionListener(this);
if(e.getSource() == yesNoBoxRem)
    {
        if(yesNoBoxRem.equals("OFF"))
            {
                yesNoBoxSenMang.setSelectedItem("OFF");
                yesNoBoxMangDir.setSelectedItem("OFF");
            }
    }

Here, I am using 3 JComboBox with ON and OFF options, How to set the 2 and 3 comboBox to OFF when First comboBox is OFF? I tried the above way but no result

Upvotes: 2

Views: 1752

Answers (4)

Alya'a Gamal
Alya'a Gamal

Reputation: 5638

Try this :

if(yesNoBoxRem.getSelectedItem()=="oFF")
    {
       yesNoBoxSenMang.setSelectedItem("OFF");
       yesNoBoxMangDir.setSelectedItem("OFF");
    }

Upvotes: 2

vijay
vijay

Reputation: 1139

if(e.getSource() == yesNoBoxRem)
    {
        if(yesNoBoxRem.getSelectedItem() == "OFF")
            {
                yesNoBoxSenMang.setSelectedItem("OFF");
                yesNoBoxMangDir.setSelectedItem("OFF");
            }
    }

Upvotes: 1

Darshit Chokshi
Darshit Chokshi

Reputation: 589

Use getSeletedItem() method instead of direct use of equals()

like below,

    if(e.getSource() == c1)
    {
        if(c1.getSelectedItem().equals("OFF"))
            {
                c2.setSelectedItem("OFF");
                c3.setSelectedItem("OFF");
            }
    }

Upvotes: 2

Harrath hichem
Harrath hichem

Reputation: 163

try to reapint those items yesNoBoxSenMang and yesNoBoxMangDir.

Upvotes: 0

Related Questions