Re-populating a JList on an ActionListener event
-
30-09-2019 - |
Question
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.
Solution
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.
OTHER TIPS
The setListData()
method allows you to reset the contents of the list.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow