Want to set default value selected in JComboBox populated by enum

放肆的年华 提交于 2019-12-07 01:03:04

问题


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..


回答1:


cbImportCountry.setSelectedItem(EbayContryEnum.FR);




回答2:


cbImportCountry.setSelectedItem(EbayContryEnum.FR);



回答3:


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");


来源:https://stackoverflow.com/questions/20651149/want-to-set-default-value-selected-in-jcombobox-populated-by-enum

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!