Example usage for javafx.stage Stage sizeToScene

List of usage examples for javafx.stage Stage sizeToScene

Introduction

In this page you can find the example usage for javafx.stage Stage sizeToScene.

Prototype

public void sizeToScene() 

Source Link

Document

Set the width and height of this Window to match the size of the content of this Window's Scene.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    Group group = new Group();
    Scene scene = new Scene(group);

    SplitPane sp = new SplitPane();
    final StackPane sp1 = new StackPane();
    sp1.getChildren().add(new Button("Button One"));
    final StackPane sp2 = new StackPane();
    sp2.getChildren().add(new Button("Button Two"));
    final StackPane sp3 = new StackPane();
    sp3.getChildren().add(new Button("Button Three"));
    sp.getItems().addAll(sp1, sp2, sp3);
    sp.setDividerPositions(0.3f, 0.6f, 0.9f);

    group.getChildren().add(sp);//from  ww w .  jav  a2 s . c  om

    stage.setTitle("Welcome to JavaFX!");
    stage.setScene(scene);
    stage.sizeToScene();
    stage.show();
}

From source file:gov.va.isaac.sync.view.SyncView.java

/**
 * @see gov.va.isaac.interfaces.gui.views.PopupViewI#showView(javafx.stage.Window)
 *//* ww  w.  j  av a  2 s.  com*/
@Override
public void showView(Window parent) {
    initGui();
    Stage stage = new Stage(StageStyle.DECORATED);
    stage.initModality(Modality.NONE);
    stage.initOwner(parent);
    Scene scene = new Scene(root_);
    stage.setScene(scene);
    stage.setTitle("Datastore Synchronization");
    stage.getScene().getStylesheets().add(SyncView.class.getResource("/isaac-shared-styles.css").toString());
    stage.sizeToScene();
    stage.show();
    stage.setOnCloseRequest(windowEvent -> {
        if (running_.get()) {
            windowEvent.consume();
        }
    });
}

From source file:Main.java

@Override
public void start(Stage stage) throws Exception {
    genderFld.getItems().addAll("Male", "Fenale", "Unknwon");

    dataFld.setPrefColumnCount(30);//w ww .j  ava  2s  .c om
    dataFld.setPrefRowCount(5);

    GridPane grid = new GridPane();
    grid.setHgap(5);
    grid.setVgap(5);

    // Place the controls in the grid   
    grid.add(fNameLbl, 0, 0); // column=0, row=0
    grid.add(lNameLbl, 0, 1); // column=0, row=1
    grid.add(bDateLbl, 0, 2); // column=0, row=2
    grid.add(genderLbl, 0, 3); // column=0, row=3

    grid.add(fNameFld, 1, 0); // column=1, row=0
    grid.add(lNameFld, 1, 1); // column=1, row=1
    grid.add(bDateFld, 1, 2); // column=1, row=2
    grid.add(genderFld, 1, 3); // column=1, row=3
    grid.add(dataFld, 1, 4, 3, 2); // column=1, row=4, colspan=3, rowspan=3

    VBox buttonBox = new VBox(saveBtn, closeBtn);
    saveBtn.setMaxWidth(Double.MAX_VALUE);
    closeBtn.setMaxWidth(Double.MAX_VALUE);

    grid.add(buttonBox, 2, 0, 1, 2); // column=2, row=0, colspan=1, rowspan=2

    saveBtn.setOnAction(e -> showData());

    closeBtn.setOnAction(e -> stage.hide());

    Scene scene = new Scene(grid);
    stage.setScene(scene);
    stage.setTitle("Person Details");
    stage.sizeToScene();
    stage.show();
}

From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java

private void showImage(File file) {

    try {//from w  w w.  j  ava  2  s  .  co  m
        ImageView iv = new ImageView(new Image(file.toURI().toURL().toString()));
        iv.setPreserveRatio(true);
        Stage stage = new Stage();

        final DoubleProperty zoomProperty = new SimpleDoubleProperty(200);

        zoomProperty.addListener(new InvalidationListener() {
            @Override
            public void invalidated(javafx.beans.Observable observable) {
                iv.setFitWidth(zoomProperty.get() * 4);
                iv.setFitHeight(zoomProperty.get() * 3);
            }
        });

        ScrollPane sp = new ScrollPane(iv);
        stage.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
            @Override
            public void handle(ScrollEvent event) {
                if (event.getDeltaY() > 0) {
                    zoomProperty.set(zoomProperty.get() * 1.1);
                } else if (event.getDeltaY() < 0) {
                    zoomProperty.set(zoomProperty.get() / 1.1);
                }
            }
        });

        stage.setScene(new Scene(new Group(sp)));

        stage.sizeToScene();
        stage.show();
    } catch (IOException ex) {
        showErrorDialog(ex);
    }

}

From source file:org.cryptomator.ui.MainApplication.java

@Override
public void start(final Stage primaryStage) throws IOException {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    Platform.runLater(() -> {/* w w  w .ja  v  a  2s .c om*/
        /*
         * This fixes a bug on OSX where the magic file open handler leads
         * to no context class loader being set in the AppKit (event) thread
         * if the application is not started opening a file.
         */
        if (Thread.currentThread().getContextClassLoader() == null) {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }
    });

    Runtime.getRuntime().addShutdownHook(MainApplication.CLEAN_SHUTDOWN_PERFORMER);

    executorService = Executors.newCachedThreadPool();
    addShutdownTask(() -> {
        executorService.shutdown();
    });

    WebDavServer.getInstance().start();
    chooseNativeStylesheet();
    final ResourceBundle rb = ResourceBundle.getBundle("localization");
    final FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"), rb);
    final Parent root = loader.load();
    final MainController ctrl = loader.getController();
    ctrl.setStage(primaryStage);
    final Scene scene = new Scene(root);
    primaryStage.setTitle(rb.getString("app.name"));
    primaryStage.setScene(scene);
    primaryStage.sizeToScene();
    primaryStage.setResizable(false);
    primaryStage.show();
    ActiveWindowStyleSupport.startObservingFocus(primaryStage);
    TrayIconUtil.init(primaryStage, rb, () -> {
        quit();
    });

    for (String arg : getParameters().getUnnamed()) {
        handleCommandLineArg(ctrl, arg);
    }

    if (org.controlsfx.tools.Platform.getCurrent().equals(org.controlsfx.tools.Platform.OSX)) {
        Main.OPEN_FILE_HANDLER.complete(file -> handleCommandLineArg(ctrl, file.getAbsolutePath()));
    }

    LocalInstance cryptomatorGuiInstance = SingleInstanceManager.startLocalInstance(APPLICATION_KEY,
            executorService);
    addShutdownTask(() -> {
        cryptomatorGuiInstance.close();
    });

    cryptomatorGuiInstance.registerListener(arg -> handleCommandLineArg(ctrl, arg));
}