我的部分代码
ArrayList<Item> i = g.getItems();
Vector itemsVector = new Vector(i);
JList items = new JList(iemsVector);
Run Code Online (Sandbox Code Playgroud)
稍后在代码中我创建了我想要添加到JList的新对象.我怎样才能做到这一点?
好吧,您不能直接使用该数组,但使用它可能会对您有所帮助。
DefaultListModel demoList = new DefaultListModel();
demoList.addElement("addElements");
JList listd = new JList(demoList);
Run Code Online (Sandbox Code Playgroud)
这样您就可以将元素添加到列表中。