简体   繁体   中英

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

I am using netbeans 6.9.1. I have a jframe, and the jframe has a jList and the DefaultListModel name is 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...?

  • I know how to add elements within the jframe class , using addElement() however from a different class i am stumped.

thanks -jason

I'm just guessing here... your question needs a little more detail as Nivas pointed out.

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类时),则应该有一个公共方法,该方法接受要添加的项目并将其添加到列表模型中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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