switch JavaFX Layout - Java JavaFX

Java examples for JavaFX:Layout

Description

switch JavaFX Layout

Demo Code


import java.io.IOException;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Window;

public class Main{
    public static void switchLayout(Stage stage, String name) {
        switchLayout(stage, name, false);
    }//from ww  w.  ja  v a2  s. co m
    public static void switchLayout(Stage stage, String name,
            boolean fullSize) {
        try {
            // Load root layout from fxml file.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(FXUtil.class.getClassLoader().getResource(
                    name + ".fxml"));
            Parent rootLayout = loader.load();

            // Show the scene containing the root layout.
            Scene scene = new Scene(rootLayout);
            stage.setScene(scene);
            if (!stage.isShowing()) {
                stage.show();
            }

            if (fullSize) {
                stage.setMaximized(true);
            } else {
                stage.setMaximized(false);
                stage.sizeToScene();
                stage.centerOnScreen();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials