辣椒风暴
2020-03-02 11:36
采纳率: 0%
浏览 196

JComboBox addItem无法识别

idea中输入的代码,软件表示无法识别,求解决方案


想在JComboBox中加入元素,如下图,发现无法识别addItem;
idea预设版本与所用JDK版本一致


图片说明


    JComboBox c1=new JComboBox();
    c1.addItem("suit one");
    c1.addItem("suit two");

附addItem JDK13.0.2:


addItem

public void addItem​(E item)

Adds an item to the item list. This method works only if the JComboBox uses a mutable data model.
Warning: Focus and keyboard navigation problems may arise if you add duplicate String objects. A workaround is to add new objects instead of String objects and make sure that the toString() method is defined. For example:

comboBox.addItem(makeObj("Item 1"));

comboBox.addItem(makeObj("Item 1"));

...

private Object makeObj(final String item) {
return new Object() { public String toString() { return item; } };
}

Parameters:

item - the item to add to the list

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

相关推荐 更多相似问题