I have a JList nested inside a JScrollPane. When I add elements to the JList, I want the JScrollPane to automatically scroll the bottom of the JList so that the last element is visible. For this, I have the following code:
getWordListScroller().getVerticalScrollBar().getModel().setValue(getWordListScroller().getVerticalScrollBar().getModel().getMaximum());
However, when I try to use this code, JScrollPane only scrolls the second to the last element, leaving the last element out of sight. This is in no way desirable. I tried adding values to getMaximum (), but the problem persists.
How can I get JScrollPane to scroll to the bottom?
source
share