Adding items to a JComboBox

后端 未结 6 629
生来不讨喜
生来不讨喜 2020-12-01 18:16

I use a combo box on panel and as I know we can add items with the text only

    comboBox.addItem(\'item text\');

But some times I need to

6条回答
  •  有刺的猬
    2020-12-01 18:57

    You can use String arrays to add jComboBox items

    String [] items = { "First item", "Second item", "Third item", "Fourth item" };
    
    JComboBox comboOne = new JComboBox (items);
    

提交回复
热议问题