简体   繁体   English

如何从另一个类向jList添加元素?

[英]How do i add elements to a jList from another class?

I am using netbeans 6.9.1. 我正在使用netbeans 6.9.1。 I have a jframe, and the jframe has a jList and the DefaultListModel name is lm. 我有一个jframe,并且jframe有一个jList,而DefaultListModel名称是lm。 I would like to add elements to this jList using another class, but i can't figure out how, and can't find anything on it online...I guess i have to find a way to get the DefaultListmodel into my class also...? 我想使用另一个类将元素添加到此jList中,但我不知道如何操作,也无法在线上找到任何内容...我想我也必须找到一种方法来将DefaultListmodel放入我的类中...?

  • I know how to add elements within the jframe class , using addElement() however from a different class i am stumped. 我知道如何在jframe类中添加元素 ,但是使用addElement()来自另一个类,我很困惑。

thanks -jason 谢谢-杰森

I'm just guessing here... your question needs a little more detail as Nivas pointed out. 我只是在这里猜测...正如Nivas指出的,您的问题需要更多细节。

But it sounds like crosses fingers you need to expose your list model as a property and manipulate that from the external class. 但这听起来像是您需要将列表模型作为属性公开并从外部类进行操纵的交叉手指

假设ListModel是在较早的阶段创建的(例如在初始化JFrame类时),则应该有一个公共方法,该方法接受要添加的项目并将其添加到列表模型中。

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

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