I am trying to change a JList inside a JScrollPane dynamically using
myList.setListData(someArray);
After that, I expected JScrollPane to show scrollbars as needed, but this will not happen. The problem with googling was not very helpful. I tried various combinations of the following methods, with little success (mostly punching api docs):
myScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
myList.validate(); myScrollPane.validate();
myScrollPane.setPreferredSize(Dimension someDimension);
myScrollPane.setViewportView(moduleList);
myScrollPane.setLayout(...);
When using the first method, a scroll bar appears, but it does not activate when the model changes. I also connected to the PropertyChangeEvent and confirmed that the JList is triggered and the event when the model has changed. What am I missing here? What method should I use to make this work, or even better, which property will make this work out of the box?
Volka