简体   繁体   中英

Re-populating a JList on an ActionListener event

Depending on what they choose in the JComboBox I want the JList to show different strings, not sure how to repopulate a JList though. When searching through the API, still found nothing.

Any idea on how you might code this?

Im using NetBeans by the way for reference.

使用setListData()方法可以重置列表的内容。

not sure how to repopulate a JList though

DefaultListModel model = new DefaultListModel(...);
// add items to the model
list.setModel( model );

Or you could use the DefaultComboBoxModel which would allow you to create with model with a Vector or Array.

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