简体   繁体   English

数组列表 <recipe> 到JList

[英]ArrayList<recipe> to JList

I have multiple recipes which I want the user to chose from (JList) and then it will show the ingredients of the recipe in another JList. 我有多个配方,希望用户从(JList)中选择,然后它将在另一个JList中显示配方的成分。

I want the recipe JList to show the name of the recipe only. 我希望食谱JList仅显示食谱的名称。 So basically I need to understand how to make a JList out of a ArrayList and show only one attribute of the object, for instance the name. 因此,基本上,我需要了解如何从ArrayList中制作JList并仅显示对象的一个​​属性,例如名称。

You could use something like so: recepies= new JList(recepiesList.toArray()) . 您可以使用类似这样的方法: recepies= new JList(recepiesList.toArray())

Then, in your Recipe class, override the toString() method to show what ever field it is you want to show. 然后,在您的Recipe类中,重写toString()方法以显示要显示的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM