Reputation: 1
I am creating a JavaFX application using a scene builder. I want to set one free size(width 200 and height 300) and full screen only. I don't want to give resize access. How I do it...??
Upvotes: 0
Views: 1860
Reputation: 1718
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
// Set the size:
Scene scene = new Scene(root, 200, 300);
// Prevent resizing:
primaryStage.setResizable(false);
// Remove the buttons for minimizing and maximizing:
primaryStage.initStyle(StageStyle.UTILITY);
// Start in full screen mode:
primaryStage.setFullScreen(true);
// Toggle between normal and full screen mode with F11 key:
scene.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.F11)
primaryStage.setFullScreen(!primaryStage.isFullScreen());
});
primaryStage.setScene(scene);
primaryStage.show();
}
Upvotes: 0
Reputation: 1332
You cannot do that using Scene Builder, fullScreen are properties of the Stage and not the layouts set on the scene.
the solution is to load and set the .fxml on the scene and then set the scene on the stage.
To set stage as full-screen, undecorated window :
primaryStage.setFullScreen(true/false);
To maximize the stage and fill the screen :
primaryStage.setMaximized(true/false);
to disable resizable screen in JavaFx try this :
primaryStage.setResizable(false);
and to make scene size width:200/height:300:
primaryStage.setScene(new Scene(root, 200 , 300));
here is a full example :
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("views/homePage.fxml"));
primaryStage.setTitle("title");
primaryStage.setScene(new Scene(root, 200 , 300));
primaryStage.setResizable(false);
primaryStage.setMaximized(true);
primaryStage.show();
}
Upvotes: 3