Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JScrollBar visible

Tags:

java

swing

Is there some way to know if a JScrollBar is visible or not inside a JPanel?

I mean, some times, my panel has many rectangles (think of 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.

like image 441
Leandro Lima Avatar asked Jan 24 '23 08:01

Leandro Lima


1 Answers

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:

  • JGraphPanel (its callback actionPerformed(Event e) will adjust the visibility based on a zoom factor)
  • Plane (its function adjustComponents() will call setVisible() on the JScrollBar if needed)
like image 119
VonC Avatar answered Jan 25 '23 22:01

VonC