Skip to content
Advertisement

Horizontal JScrollPane inside vertical JScrollPane

Good afternoon! It is necessary to make a list (vertical) from lists of events (horizontal). There are at least 2 problems:

  1. the area of the list of events (horizontal scrolling) expands beyond the borders of the panel. Apparently, the problem is with Layout, but I can not find the right combination;
  2. horizontal scrolling does not work (probably due to the problem described above) and the scrollbar must be different for each group of events.
JavaScript
JavaScript

What I have: enter image description here What I want to get: enter image description here

Advertisement

Answer

A scrolling area inside another scrolling area is a user interface antipattern (anti-design?). It should be avoided.

I would create a scrollable panel based on a vertical BoxLayout:

JavaScript

The CameraListPanel class is mostly a basic scrollable panel; the important part is that getScrollableTracksViewportWidth() returns true, which will cause the panel’s width to match the width of any JScrollPane viewport. This eliminates any need for a horizontal scrollbar.

Of course, you will want to show all of your child components somehow. To do that, I would have the EventAdd class compute a height that can accommodate all of the children:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement