Want to set default value selected in JComboBox populated by enum
Asked Answered
C

3

8

Below statement in if condition is not working, please provide me some solution that how to set selected item for JComboBox which are populated by ENUM.

      public enum EbayContryEnum 
        {
        AT    (3),
        AU    (4),
        BE    (5),
        CA    (7),
        CH    (14),
        DE    (11),
        ES    (13),
        FR    (10),
        IE    (2),
        IT    (12),
        NL    (16),
        UK    (15),
        US    (1);
        }

for ex:-

if(country.equals("FR"))
                      {
                      cbImportCountry.setSelectedItem("FR");
                      }

But it's not working..

Copyreader answered 18/12, 2013 at 6:33 Comment(0)
R
12

cbImportCountry.setSelectedItem(EbayContryEnum.FR);

Ransom answered 18/12, 2013 at 9:18 Comment(1)
If the Value is comming from database then how we will set its the selected values..???Avellaneda
G
9
cbImportCountry.setSelectedItem(EbayContryEnum.FR);
Geometric answered 18/12, 2013 at 6:35 Comment(1)
If the Value is comming from database then how we will set its the selected values..???Avellaneda
M
1

Maybe you are not looking for assign the value to the combobox. You are looking for casting your value to the enum.

You can do this via:

EbayContryEnum.valueOf("FR");
Military answered 18/2, 2018 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.