tags:

views:

134

answers:

2
+2  Q: 

Scrollbar visible

Is there some way to know if a scrollbar is visible or not inside a JPanel? I mean, some times, my panel has many rectangles (think it as buttons) and needs a scrollbar and some times it doesn't need it. I'd like to know if I can know when it is being shown.

+1  A: 

If you extend the JPanel and add yourself the JScrollbars (horizontal and/or vertical), then you can control when they must be visible or invisible
(you can check if they are currently visible with the isvisible() function)

You can find two example of such classes that determine the need for visible scrollbar depending on their content:

VonC
A: 

Assuming you have a reference to a JScrollPane, you should be able to just call

yourJScrollPane.getHorizontalScrollBar().isVisible() and yourJScrollPane.getVerticalScrollBar().isVisible()

Joshua McKinnon