When I try setting the JList visibility to false to hide the content, I discover that the list is not hidden entirly when I scroll down. I have tried validate() and repaint() of JList, JScrollPane and JPanel (MainPanel), but no changes, I have also tried this:
jScollPane.setVerticalScrollBarPolicy(
javax.swing.ScrollPaneCantants.HORIZONTAL_SCROLLBAR_NEVER);
Also, no results. Some elements of the list remain visible if I scroll down the scroll bar.
I see at least two ways to do that:
JListfrom the scrollpane:scrollPane.setViewPortView(null);JListto an empty model:list.setModel(new DefaultListModel());Another alternative is to change the scroll mode of the
JViewPort:but of course this is not efficient at all. If you use that solution, when you make your component visible again, make sure to also properly reset the scroll mode to
BLIT_SCROLL_MODEorBACKINGSTORE_SCROLL_MODEwhich are much more efficient.