5

This code will create a 3d scene that is 300x300 large. The viewport won't resize when I resize the containing window/stage.

Parent doesn't have any width or height properties. How do I adjust the size of the Parent and/or SubScene to the changing window size?

4 Answers 4

11

bind it to the parent

SubScene subscene = new SubScene(root, 1024, 768, true, null); subscene.setFill(Color.GREY); subscene.setCamera(camera); StackPane stackPane = new StackPane(); stackPane.getChildren().add(subscene); subscene.heightProperty().bind(stackPane.heightProperty()); subscene.widthProperty().bind(stackPane.widthProperty()); 
Sign up to request clarification or add additional context in comments.

3 Comments

I found out about that some time ago, but thanks nevertheless.
Parent class does not contain a heightProperty() or widthProperty().
what parent class are you using? can you add a stackpane inside the parent class and then bind subscene?
6

I found it is also important to set the managed property of the SubScene object to false.

subscene.setManaged(false); 

This way, the SubScene object's size will not impact the size of its parent StackPane object and resizing will also work when reducing the StackPane object's size.

1 Comment

Just what I needed to shrink the sub scene
0

With the following approach you can put your SubScene into any class that extends the Pane class (e.g. BorderPane, GridPane, etc.). Also the subScene can have a different size from your Pane:

public class GuiControler extends BorderPane implements Initializable,ChangeListener { //Set a changeListener to the Stage's Window and Implement the ChangeListener in the class where you want to make the subScene scaling. stage.widthProperty().addListener(this); stage.heightProperty().addListener(this); //.... @Override public void changed(ObservableValue observable, Object oldValue, Object newValue) { double width = stage.getWidth(); double height = stage.getHeight(); if(observable.equals(this.widthProperty())) { double scale = width / 400; // 400 is my initial width size of the stage (main java app window) window subScene.setWidth(200*scale); // 200 is my initial size of the subscene window }else if(observable.equals(this.heightProperty())){ double scale = height / 400; // 400 is initial size for stage height window subScene.setHeight(250*scale); // 250 is initial size for subScene width } } } 

Comments

-1

Ypu may want to use getTransforms().add(new Scale(parameter1, para2,...));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.