如何将ArrayList绑定到JList [英] how to bind ArrayList to JList
本文介绍了如何将ArrayList绑定到JList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JList和ArrayList.如何将arraylist中的数据绑定到jlist.是否有其他替代方法?
i have a JList and an ArrayList.How to bind the datas in arraylist to the jlist.Are the any alternative methods?
ArrayList arl = new ArrayList();
arl.add("1asdsd");
arl.add("2asdsd");
arl.add("3asdsd");
Object obj = arl.clone();
JList list = new JList(obj);
如何绑定以上代码.现在代码给出错误.
how to bind the above code.Now the code give an error.
推荐答案
您无需克隆ArrayList.只需调用toArray()
You don't need to clone the ArrayList. Just call toArray()
JList list = new JList(arl.toArray());
这篇关于如何将ArrayList绑定到JList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文