How do I get a JScrollPane to always display scroll bars?

Java, Swing, Tip 6.11.2015 No Comments

You can achieve this by setting the scroll bar policy on both the verical and horizontal scroll bars.


JScrollPane scrollPane = new JScrollPane(panel);
    
// Force the scrollbars to always be displayed

scrollPane.setHorizontalScrollBarPolicy(
   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(
   JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 

Leave a Reply

s2Member®