vondip
vondip

Reputation: 14039

javafx scrollbar

I'm very new to javafx. I am trying to add a horizontal scroll bar to my stage. I've got a very wide picture and I'd like to show only part of it and allow the user to scroll it. How is it done?

Upvotes: 0

Views: 1014

Answers (3)

Kaito
Kaito

Reputation: 326

Image roses = new Image(getClass().getResourceAsStream("roses.jpg"));
ScrollPane sp = new ScrollPane();
sp.setContent(new ImageView(roses)); //result 1

sp.setHbarPolicy(ScrollBarPolicy.NEVER);// add for result 2
sp.setVbarPolicy(ScrollBarPolicy.ALWAYS);

Result:

enter image description here

Result with setHbarPolicy and setVbarPolicy:

enter image description here

greetings Kaito

Upvotes: 1

LuCG
LuCG

Reputation: 109

You could use a ScrollPane and inside that ScrollPane put your picture.

In the Scenebuilder:

AnchorPane -->ScrollPane --> AnchorPane (with Big Picture)

Upvotes: 0

Rastislav Komara
Rastislav Komara

Reputation: 1721

You can try to bind value of scrollbar to translateX (or Y) of image. And of course set min and max of scrollbar to 0, image.width (.height)

Upvotes: 1

Related Questions