JList list;
list=new JList();
list.add("string");
我无法运行程序(出现错误)。错误说:当我将项目添加到JList时,为什么会出现错误?
The method add(Component) in the type `Container` is not applicable for the arguments (int)
我尝试使用JList<String>
,但它仍然无法正常工作? 谢谢!
JList list;
list=new JList();
list.add("string");
我无法运行程序(出现错误)。错误说:当我将项目添加到JList时,为什么会出现错误?
The method add(Component) in the type `Container` is not applicable for the arguments (int)
我尝试使用JList<String>
,但它仍然无法正常工作? 谢谢!
您不能直接将数据添加到JList
。
改为使用ListModel
。
DefaultListModel<String> listModel = new DefaultListModel<String>();
list.setModel(listModel);
// Add elements to the Model
listModel.addElement("hello");
什么是列表模式?我试图从各种谷歌搜索了解它,但我不明白。它与模型 - 视图 - 控制有关,对吗? –
做一个数组项目添加到:
arraylist string = new arraylist [size that you want];
arraylist.add (what u want to add in here);
名单VS JList的.. –