Example usage for javafx.stage Stage close

List of usage examples for javafx.stage Stage close

Introduction

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

Prototype

public void close() 

Source Link

Document

Closes this Stage .

Usage

From source file:pe.edu.system.jcmr.util.UtilidadesFx.java

public void closeWindow(Node node) {

    Stage stage = (Stage) node.getScene().getWindow();
    stage.close();
}

From source file:pe.edu.system.jcmr.util.UtilidadesFx.java

public void closeWindow(ActionEvent event) {

    Node source = (Node) event.getSource();
    Stage stage = (Stage) source.getScene().getWindow();
    stage.close();

}

From source file:ExcelFx.XLSSettingController.java

@FXML
protected void okButton(ActionEvent event) throws IOException {

    DropShadow ds = new DropShadow();
    ds.setColor(Color.RED);//ww  w.j a  v  a  2 s  . com

    String err = "";
    try {
        if (pageField.getText().length() == 0) {
            err += " ";
            pageField.setEffect(ds);

        }
    } catch (Exception ex) {
        err += " ";
        pageField.setEffect(ds);
    }
    try {
        if (eddWayField.getText().length() == 0) {
            err += "?  ";
            eddWayField.setEffect(ds);

        }
    } catch (Exception e) {
        err += "?  ";
        eddWayField.setEffect(ds);
    }
    try {
        if (proffField.getText().length() == 0) {
            err += "??? ";
            proffField.setEffect(ds);
        }
    } catch (Exception ex) {
        err += "??? ";
        proffField.setEffect(ds);
    }
    //        try {
    //            if (eddNameField.getText().length() == 0) {
    //                err += "? ?  ";
    //                eddNameField.setEffect(ds);
    //            }
    //        } catch (Exception ex) {
    //            err += "??? ";
    //            eddNameField.setEffect(ds);
    //        }

    if (err.length() != 0) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("");
        alert.setHeaderText("? ?");
        alert.setContentText(err);
        alert.showAndWait();

    } else {

        json.setPage(pageField.getText().trim().toLowerCase());
        json.setEddWay(eddWayField.getText().trim().toLowerCase());
        json.setProffName(proffField.getText().trim().toLowerCase());
        //            json.setEddName(this.eddNameField.getText().trim().toLowerCase());
        gridPane.setUserData(json);
        Stage stage = (Stage) gridPane.getScene().getWindow();
        stage.close();

    }

    switch (type) {
    case "university": {
        json.jsonCreate("university.json");
        break;

    }
    case "college": {
        json.jsonCreate("college.json");
        break;

    }

    }

}

From source file:jlotoprint.MainViewController.java

@FXML
public void handleOpenTemplateAction(ActionEvent event) {
    final Stage templateChooser = MainViewController.loadTemplateChooser();
    if (templateChooser != null) {
        templateChooser.getScene().getRoot().addEventHandler(TemplateDialogEvent.SELECTED, (actionEvent) -> {
            templateChooser.close();
            Template.load(true);//from  ww  w  .j av  a  2  s  . c om
        });
    }
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Text text = new Text("!");
    text.setFont(new Font(40));
    VBox box = new VBox();
    box.getChildren().add(text);/* w w  w  .  j  a v a  2 s  .  co m*/
    final Scene scene = new Scene(box, 300, 250);
    scene.setFill(null);
    stage.setScene(scene);
    stage.show();
    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        public void handle(WindowEvent we) {
            System.out.println("Stage is closing");
        }
    });
    stage.close();

}

From source file:org.beryx.viewreka.fxapp.ProjectLibs.java

private void closeProgress(Stage stage, InstallLibsTask task) {
    stage.close();

    Worker.State state = task.getState();
    List<Pair<String, Throwable>> problems = task.getProblems();
    if (problems.isEmpty() && state == Worker.State.SUCCEEDED)
        return;/*from  w ww .  j av a 2  s. c o  m*/
    String message = (state == Worker.State.CANCELLED) ? "Installation cancelled"
            : "Problems occurred during the installation";
    Throwable t = task.getException();
    if (!problems.isEmpty()) {
        message += ":\n\t" + problems.stream().map(pair -> pair.getKey()).collect(Collectors.joining("\n\t"));
        if (t == null) {
            t = problems.get(0).getValue();
        }
    }
    Dialogs.error("Project created with problems", message, t);
}

From source file:ExcelFx.FXMLDocumentController.java

@FXML
private void Close(ActionEvent event) throws IOException {

    Stage stage = (Stage) this.SplitPane.getScene().getWindow();
    stage.close();

}

From source file:jlotoprint.MainViewController.java

@FXML
public void handleOpenTemplateDesigner(ActionEvent event) {

    try {/*from   w  w  w  . j a va 2  s.  c  o m*/
        FXMLLoader dialog = new FXMLLoader(MainViewController.class.getResource("TemplateDesigner.fxml"));
        Parent root = (Parent) dialog.load();
        final Stage stage = new Stage();
        stage.setOnCloseRequest((WindowEvent windowEvent) -> {
            boolean shouldClose = ((TemplateDesignerController) dialog.getController()).showSaveChangesDialog();
            //cancel event
            if (!shouldClose) {
                windowEvent.consume();
            }
        });
        root.addEventHandler(TemplateDesignerEvent.CLOSE, actionEvent -> {
            stage.close();
        });
        stage.setScene(new Scene(root));
        stage.getIcons().add(new Image("file:resources/icon.png"));
        stage.setTitle("Template Designer");
        stage.initModality(Modality.APPLICATION_MODAL);
        stage.initOwner(JLotoPrint.stage.getScene().getWindow());
        stage.show();
    } catch (IOException ex) {
        Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:nl.mvdr.umvc3replayanalyser.gui.ErrorMessagePopup.java

/**
 * Handles an exception that caused program startup to fail, by showing an error message to the user.
 * //  ww  w.j a  v  a  2  s.c  o  m
 * @param title
 *            title for the dialog
 * @param errorMessage
 *            error message
 * @param stage
 *            stage in which to show the error message
 * @param exception
 *            exception that caused the error
 */
public static void show(String title, String errorMessage, final Stage stage, Exception exception) {
    log.info("Showing error message dialog to indicate that startup failed.");

    // Create the error dialog programatically without relying on FXML, to minimize the chances of further failure.

    stage.setTitle(title);

    // Error message text.
    Text text = new Text(errorMessage);

    // Text area containing the stack trace. Not visible by default.
    String stackTrace;
    if (exception != null) {
        stackTrace = ExceptionUtils.getStackTrace(exception);
    } else {
        stackTrace = "No more details available.";
    }
    final TextArea stackTraceArea = new TextArea(stackTrace);
    stackTraceArea.setEditable(false);
    stackTraceArea.setVisible(false);

    // Details button for displaying the stack trace.
    Button detailsButton = new Button();
    detailsButton.setText("Details");
    detailsButton.setOnAction(new EventHandler<ActionEvent>() {
        /** {@inheritDoc} */
        @Override
        public void handle(ActionEvent event) {
            log.info("User clicked Details.");
            stackTraceArea.setVisible(!stackTraceArea.isVisible());
        }
    });

    // OK button for closing the dialog.
    Button okButton = new Button();
    okButton.setText("OK");
    okButton.setOnAction(new EventHandler<ActionEvent>() {
        /** {@inheritDoc} */
        @Override
        public void handle(ActionEvent event) {
            log.info("User clicked OK, closing the dialog.");
            stage.close();
        }
    });

    // Horizontal box containing the buttons, to make sure they are always centered.
    HBox buttonsBox = new HBox(5);
    buttonsBox.getChildren().add(detailsButton);
    buttonsBox.getChildren().add(okButton);
    buttonsBox.setAlignment(Pos.CENTER);

    // Layout constraints.
    AnchorPane.setTopAnchor(text, Double.valueOf(5));
    AnchorPane.setLeftAnchor(text, Double.valueOf(5));
    AnchorPane.setRightAnchor(text, Double.valueOf(5));

    AnchorPane.setTopAnchor(stackTraceArea, Double.valueOf(31));
    AnchorPane.setLeftAnchor(stackTraceArea, Double.valueOf(5));
    AnchorPane.setRightAnchor(stackTraceArea, Double.valueOf(5));
    AnchorPane.setBottomAnchor(stackTraceArea, Double.valueOf(36));

    AnchorPane.setLeftAnchor(buttonsBox, Double.valueOf(5));
    AnchorPane.setRightAnchor(buttonsBox, Double.valueOf(5));
    AnchorPane.setBottomAnchor(buttonsBox, Double.valueOf(5));

    AnchorPane root = new AnchorPane();
    root.getChildren().addAll(text, stackTraceArea, buttonsBox);

    stage.setScene(new Scene(root));

    // Use a standard program icon if possible.
    try {
        stage.getIcons().add(Icons.get().getRandomPortrait());
    } catch (IllegalStateException e) {
        log.warn("Failed to load icon for error dialog; proceeding with default JavaFX icon.", e);
    }

    stage.show();

    // Default size should also be the minimum size.
    stage.setMinWidth(stage.getWidth());
    stage.setMinHeight(stage.getHeight());

    log.info("Error dialog displayed.");
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@Override
public void initialize(URL location, ResourceBundle resources) {
    // Table Study
    initializeTable(tableStudy, StudyImpl.class);
    initializeTable(tablePlate, PlateImpl.class);
    initializeTable(tableSample, SampleImpl.class);
    initializeTable(tableInjection, InjectionImpl.class);
    initializeTable(tableCompound, CompoundImpl.class);
    initializeTable(tableHistory, OperationHistoryImpl.class);

    menuBar.setUseSystemMenuBar(true);//from  ww w  .  jav  a 2  s .  com

    commandManager = new CommandManager();
    commandManager.setContext(commandManagerContext);
    final GUICommandPaneFactory commandPaneFactory = new GUICommandPaneFactory(commandManager);
    MetabolomeQC.addCorrectionCommands(commandManager);
    for (Map.Entry<String, Class> commend : commandManager.getCommands().entrySet()) {
        MenuItem menuItem = new MenuItem(commend.getKey());
        menuItem.setText(commend.getKey());
        menuItem.setOnAction(e -> {
            final Stage stage = new Stage();
            stage.initModality(Modality.WINDOW_MODAL);

            Parent guiCommand = commandPaneFactory.getCommandPane(commend.getKey(),
                    (commandEvent, managedCommand) -> {
                        stage.close();
                    });
            BorderPane margins = new BorderPane(guiCommand);
            BorderPane.setMargin(guiCommand, new Insets(10));

            stage.setScene(new Scene(margins));
            stage.initOwner(this.stage);
            stage.showAndWait();
            onRefresh(null);
        });
        correctionMenu.getItems().add(menuItem);
    }

    onRefresh(null);
}