简体   繁体   English

JavaFX场景在“场景”构建器中的缩放比例与Windows 10上的运行时间不同

[英]JavaFX scene scales differently in Scene builder and run time on Windows 10

I using Scene Builder with Intelij IDEA to build a JavaFX application. 我使用Scene Builder和Intelij IDEA构建JavaFX应用程序。 The scene looks correct when I preview it in Scene Builder but when I then execute it in IntelliJ the scene is scaled up 1.5x. 当我在Scene Builder中预览时,场景看起来是正确的,但是当我在IntelliJ中执行它时,场景会按比例放大1.5倍。 In Scene Builder the stage is 1280x800 but when I run the program it is 1920x1200 despite me setting the scene size 1280x800. 在Scene Builder中,舞台是1280x800,但是当我运行程序时它是1920x1200,尽管我设置场景大小为1280x800。

This seems like it might be due to Windows 10 scaling the application. 这似乎可能是由于Windows 10扩展应用程序。 If so, is there a way to stop my application from scaling? 如果是这样,有没有办法阻止我的应用程序缩放?

Thank you! 谢谢!

@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(new Scene(root, 1280, 800));
    primaryStage.show();
}

It has nothing to do with windows scaling. 它与Windows缩放无关。 all you have to do is to remove these arguments inside your Scene ie 1280 and 800, but don't remove root. 您所要做的就是在场景中删除这些参数,即1280和800,但不要删除root。

new code will be like - 新代码将像 -

    @Override
    public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(new Scene(root);
    primaryStage.show();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM