Reputation: 14039
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
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:
Result with setHbarPolicy and setVbarPolicy:
greetings Kaito
Upvotes: 1
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
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