如何将项目从对象的ArrayList添加到JList. [英] How to add Items from an ArrayList of Objects to a JList.

查看:169
本文介绍了如何将项目从对象的ArrayList添加到JList.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过for循环将ObjectsArraylist中的项目中的toStrings添加到Jlist中.我尝试过了.

I want to add the toStrings from items in an Arraylist of Objects to a Jlist through a for loop. I tried this.

for (int i = 0; i < customer.slist.size(); i++) {
        ((DefaultListModel) checkOutList.getModel()).addElement(customer.slist.toString());//slist is an array of objects.
    }

但是它没有用.另外,当我尝试

But it didnt work. Also NetBeans tells me .addElement()is not a method for a JList when I tried

checkOutList.addElement("anything")

推荐答案

而不是

customer.slist.toString()

customer.slist.toString()

尝试:

customer.slist.get(i).toString();

customer.slist.get(i).toString();

在您的代码中.

这篇关于如何将项目从对象的ArrayList添加到JList.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆