How to use Map element as text of a JComboBox

前端 未结 3 1819
别跟我提以往
别跟我提以往 2020-12-03 15:20

I am populating a JComboBox (using addItem()) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBo

3条回答
  •  清歌不尽
    2020-12-03 16:06

    If you have a hashmap, you will want to do something like:

    JComboBox box = new JComboBox(hashMap.getValues().toArray());
    

    Of course, you have to override the toString method of the object you have in the HashMap

提交回复
热议问题