[英]JavaFx: How to keep the window maximizing?
I used primaryStage.setMaximized(true);
我使用
primaryStage.setMaximized(true);
after calling show();
调用
show();
method in Java 8 implementation. Java 8实现中的方法。 It keeps other scenes maximizing.
它使其他场景最大化。
I had the same problem. 我有同样的问题。 I fixed it creating a root stage with that only contains a menu bar and a tool bar, like this:
我修复了它创建的根阶段,其中仅包含菜单栏和工具栏的情况,如下所示:
I initialized this window in the start method with: 我在start方法中使用以下命令初始化了该窗口:
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/RootLayout.fxml"));
rootLayout = (BorderPane) loader.load();
RootController controller= loader.getController();
// Show the scene containing the root layout.
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
Later, when you want to load a FXML file or scene into the root container, you could make it with the next lines in another method: 稍后,当您要将FXML文件或场景加载到根容器中时,可以使用另一种方法的下几行将其制成:
FXMLLoader loader = new FXMLLoader();
loader.setLocation(Main.class.getResource("view/principal.fxml"));
AnchorPane principalOverview = (AnchorPane) loader.load();
// Set person overview into the center of root layout.
rootLayout.setCenter(principalOverview);
// Get the controller instance
controllerPrincipal = loader.getController();
in that way every scene you add to the root stage will get the size of the root. 这样,您添加到根阶段的每个场景都将获得根的大小。
This is how I did it: 这是我的方法:
@FXML
private Button goBtn;
Stage stage = (Stage) goBtn.getScene().getWindow();
Scene scene = goBtn.getScene();
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Activity.fxml"));
scene.setRoot(loader.load());
stage.setScene(scene);
stage.show();
} catch (IOException e) {
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.