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!

Scaling in JavaFX

user8731736Jan 29 2018 — edited Feb 3 2018

Hi JavaFXers,

I'm struggling with properly scaling a JavaX stage, I was hoping that this I'm just missing something simple, and someone can help me out.

This simple application shows what I mean:

public class ScaleTest extends Application {

    @Override

    public void start(Stage primaryStage) {

        GridPane grid = new GridPane();

        grid.setAlignment(Pos.CENTER);

        grid.add(new Text("Hello"), 0, 0, 2, 1);

        grid.setBorder(new Border(new BorderStroke(Color.RED,

                BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));

        Scene scene = new Scene(grid, 300, 275);

        primaryStage.setScene(scene);

        primaryStage.show();

        grid.getTransforms().add(new Scale(0.8, 0.8, 0, 0));

    }

}

What happens is that when setting up the scaling for the pane in the scene, it gets scaled withing the window, Resizing the window doesn't help, because the inner pane just updates it's size. So basically there is a dead space between the pane and the window. My expectation would be to be able the scale the layout, with keeping its behaviour to its container's outer bounds.

I hope I'm making sense, and someone can help me understanding how this should be done.

Thanks a lot!

Szabolcs

This post has been answered by jsmith on Feb 1 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 3 2018
Added on Jan 29 2018
5 comments
11,218 views