Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

java - JavaFX: Why does stage.setResizable(false) cause additional margins?

This small JavaFX test application

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class ApplicationWithNonResizableStage extends Application {

    public static void main(final String[] args) {
        launch(args);
    }

    @Override
    public void start(final Stage primaryStage) throws Exception {
        final Rectangle rectangle = new Rectangle(200, 100, Color.POWDERBLUE);
        final BorderPane pane = new BorderPane(rectangle);
        final Scene scene = new Scene(pane);
        primaryStage.setScene(scene);
        primaryStage.setResizable(false);
        primaryStage.show();
    }
}

produce a window with unwanted padding:

stage with margin

Removing the call primaryStage.setResizable(false) also removes the effect:

stage without margin

What is going wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As already commented, this different behaviour of !/resizable smells like a bug (somebody might consider filing an issue ;-)

A shorter (than sizing manually) way around is to explicitly fit the stage to the scene:

primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.sizeToScene();

Just noticed that this works for jdk8, but not jdk7.

For convenience, a bug update: the original report filed by jewelsea was closed as a duplicate of (in new coordinates) https://bugs.openjdk.java.net/browse/JDK-8089008 - still open, commented to be win-only.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...