Skip to content

Scroll panels

Juuxel edited this page Sep 24, 2020 · 2 revisions

Scroll panels (WScrollPanel) provide scroll bars for another widget inside them. For example, you might have a tall WPanel that needs to be scrolled.

WPanel myTallPanel = <...>;
WScrollPanel scrollPanel = new WScrollPanel(myTallPanel);

root.add(scrollPanel, 0, 1);

You can also control which scroll bars appear. By default, both scroll bars are in automatic mode (TriState.DEFAULT), which means that they will appear if needed. You can change this behavior with setScrollingHorizontally and setScrollingVertically.

Both methods take a TriState from Fabric API where TRUE is "always show", FALSE is "never show" and DEFAULT is the automatic mode.

We can use the methods to make our tall panel always scroll vertically but never horizontally:

scrollPanel.setScrollingHorizontally(TriState.FALSE);
scrollPanel.setScrollingVertically(TriState.TRUE);