Reputation: 177
I need to maximize Stage on load via code.
Here is my code:
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Контрола трошкова кућног буџета");
primaryStage.setMaximized(true);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
I have all needed imports. Problem is when run it primaryStage blink for a part of second in size created in Scene Builder, then maximize as intended and I want it to show Maximized. It happend in Eclipse and when make runnable JAR and run it with *.bat file.
Is there anything I am doing wrong?
For testing I created small app in WPF it works properly, no blinking.
EDIT: When stage is in normal size and I click Maximize button, it maximizes stage as I want. Is there possibility to write code to simulate or call Maximize button on top of window? Othere way besides
stage.setMaximized(true);
because that line doesn't work well.
Upvotes: 0
Views: 210
Reputation: 4258
Here is a workaround, set the stage's opacity to 0 before showing it so the resizing happens while the stage is not visible, then change it back to 1:
primaryStage.setOpacity(0);
primaryStage.show();
primaryStage.setOpacity(1);
Upvotes: 1