Search code examples
swinghidejscrollpanejscrollbar

How to make JScrollPane JScrollBar act like osx scrollbars that only show on mouse over


I want to minimize the real-estate that scroll bars are taking up in my swing application. Is there any way to have them perform like osx scroll bars that only show on mouse over? Otherwise is there a way to just not show them but still be able to scroll?

thanks


Solution

  • you can use the getVerticalScrollBar().setVisible(false) and SetWheelScrollingEnabled(boolean handleWheel) methods. But if you want you display them when they are in use than that's a bit tricky. you will have to add a mouseListener for the mouseWheel and create a 2D graphics component. if u just show and hide a normal JScrollBar (using the setVisible(boolean visible) method) the viewing area will also change and it'll look very abrupt. U will need to create an overlay using the paint()/repaint() methods.