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