dan14941
dan14941

Reputation: 332

LibGDX physical scroll bar ScrollPane

I have created a ScrollPane but there is no bar to scroll with (like the one on the side of your browser) you have to drag with your mouse. How can I get a scroll bar?

Upvotes: 7

Views: 4426

Answers (3)

JohnyTex
JohnyTex

Reputation: 3481

The bar is enabled via the skin:

Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
ScrollPane scrollPane=new ScrollPane(resultsTextArea, skin);

I tried. It works now...

Upvotes: 4

dan14941
dan14941

Reputation: 332

What I did to add a scrollbar was use libgdx's ScrollPane.ScrollPaneStyle to set the scroll bar as a ninepatch.

ScrollPane.ScrollPaneStyle scrollStyle;
/...

scrollTexture = new Texture(Gdx.files.internal("Scroll9.png"));
scrollNine = new NinePatch(new TextureRegion(scrollTexture,6,6),2,2,2,2);

then I created the vertical scroll knob

scrollStyle = new ScrollPane.ScrollPaneStyle();
scrollStyle.vScrollKnob = new NinePatchDrawable(box);

and applied the style to my scrollable table

scroll = new ScrollPane(test, scrollStyle);

source: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.ScrollPaneStyle.html

Upvotes: 5

p.streef
p.streef

Reputation: 3815

This is untested!

It seems that using the following enables scrollbars for a scrollpane.

boolean enable_x = true;
boolean enable_y = true;
scrollpane.setForceScroll(enable_x,enable_y);

source: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.html

Upvotes: 0

Related Questions