Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I create an infinite drawing canvas in a ScrollPane?

jrguentherOct 2 2013 — edited Oct 2 2013

I wanted to figure this out on my own, but it is time to ask for help. I've tried too many different things. The closest I've come to the behaviour I want is with this code:

final BorderPane root = new BorderPane();


final Pane canvasWrapper = new Pane();

canvasWrapper.setPrefSize(800, 500);

canvasWrapper.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

canvasWrapper.setStyle("-fx-background-color: lightgray; -fx-border-color: green; -fx-border-width: 2px;");

               

final Group canvas = new Group();

canvasWrapper.getChildren().add(canvas);

final ScrollPane scroll = new ScrollPane();

scroll.setContent(canvasWrapper);

     

root.setCenter(scroll);

// event code for adding circles and lines to the canvas

I want the ScrollPane to be filled with the Pane, so it can catch events for drawing. When the stage is resized, the ScrollPane is resized too. This the result of the BorderPane. What I want is to expand the window and have canvasWrapper expand to fill the entire ScrollPane viewport. When the stage is made smaller the ScrollPane shrinks, but I want the canvasWrapper to retain its size. The idea is the drawing canvas can only grow. When it gets too large for the current stage/ScrollPane size, the scrollpane can be used to navigate around the canvas.

I tried using

scroll.setFitToHeight(true);

scroll.setFitToWidth(true);

but this causes the Pane to be made smaller when the viewport is made smaller.

This post has been answered by jrguenther on Oct 2 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 30 2013
Added on Oct 2 2013
1 comment
952 views