Java Code Examples for javafx.stage.Stage#showAndWait()

The following examples show how to use javafx.stage.Stage#showAndWait() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlertBox.java    From SmartCity-ParkingManagement with Apache License 2.0 6 votes vote down vote up
public void display(final String title, final String message) {
	window = new Stage();
	window.initModality(Modality.APPLICATION_MODAL);
	window.setTitle(title);
	window.setMinWidth(250);
	window.setMinHeight(100);
	window.getIcons().add(new Image(getClass().getResourceAsStream("Smart_parking_icon.png")));

	final Label label = new Label();
	label.setText(message);
	final Button button = new Button("OK");
	button.setOnAction(λ -> window.close());
	final VBox layout = new VBox();
	layout.getChildren().addAll(label, button);
	layout.setAlignment(Pos.CENTER);

	final Scene scene = new Scene(layout);
	scene.getStylesheets().add(getClass().getResource("mainStyle.css").toExternalForm());
	window.setScene(scene);
	window.showAndWait();
}
 
Example 2
Source File: UiHelper.java    From tcMenu with Apache License 2.0 6 votes vote down vote up
public static void createDialogStateAndShowSceneAdj(Stage parent, Pane root, String title, boolean modal,
                                                    BiConsumer<Scene, Stage> sceneAdjuster) {
    Stage dialogStage = new Stage();
    dialogStage.setTitle(title);
    dialogStage.initOwner(parent);

    Scene scene = new Scene(root);
    sceneAdjuster.accept(scene, dialogStage);

    dialogStage.setScene(scene);
    if (modal) {
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.showAndWait();
    }
    else {
        dialogStage.show();
    }
}
 
Example 3
Source File: MenuControllerApp.java    From tcMenu with Apache License 2.0 6 votes vote down vote up
private RemoteMenuController showConfigChooser(MenuTree tree) throws Exception {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/remoteSelector.fxml"));
    BorderPane pane = loader.load();
    RemoteSelectorController controller = loader.getController();
    controller.init(tree);

    Stage dialogStage = new Stage();
    dialogStage.getIcons().add(new Image(getClass().getResourceAsStream("/controller-icon.png")));
    dialogStage.setTitle("Connect to tcMenu device");
    dialogStage.initModality(Modality.WINDOW_MODAL);
    dialogStage.initOwner(null);
    Scene scene = new Scene(pane);
    dialogStage.setScene(scene);
    dialogStage.showAndWait();
    return controller.getResult();
}
 
Example 4
Source File: GuiUtils.java    From thundernetwork with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void runAlert(BiConsumer<Stage, AlertWindowController> setup) {
    try {
        // JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
        // files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
        // an odd sort of way.
        Stage dialogStage = new Stage();
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
        Pane pane = loader.load();
        AlertWindowController controller = loader.getController();
        setup.accept(dialogStage, controller);
        dialogStage.setScene(new Scene(pane));
        dialogStage.showAndWait();
    } catch (IOException e) {
        // We crashed whilst trying to show the alert dialog (this should never happen). Give up!
        throw new RuntimeException(e);
    }
}
 
Example 5
Source File: GuiUtils.java    From thunder with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void runAlert (BiConsumer<Stage, AlertWindowController> setup) {
    try {
        // JavaFX2 doesn't actually have a standard alert template. Instead the Scene Builder app will create FXML
        // files for an alert window for you, and then you customise it as you see fit. I guess it makes sense in
        // an odd sort of way.
        Stage dialogStage = new Stage();
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        FXMLLoader loader = new FXMLLoader(GuiUtils.class.getResource("alert.fxml"));
        Pane pane = loader.load();
        AlertWindowController controller = loader.getController();
        setup.accept(dialogStage, controller);
        dialogStage.setScene(new Scene(pane));
        dialogStage.showAndWait();
    } catch (IOException e) {
        // We crashed whilst trying to show the alert dialog (this should never happen). Give up!
        throw new RuntimeException(e);
    }
}
 
Example 6
Source File: CurlyApp.java    From curly with Apache License 2.0 6 votes vote down vote up
public static void importWizard(Consumer<List<Map<String, String>>> handler) {
    try {
        FXMLLoader loader = new FXMLLoader(CurlyApp.class.getResource("/fxml/DataImporter.fxml"));
        loader.setResources(ApplicationState.getInstance().getResourceBundle());
        loader.load();
        DataImporterController importController = loader.getController();

        Stage popup = new Stage();
        popup.setScene(new Scene(loader.getRoot()));
        popup.initModality(Modality.APPLICATION_MODAL);
        popup.initOwner(applicationWindow);

        importController.setActions(appController.getActions());
        importController.setFinishImportHandler(handler);
        importController.whenFinished(popup::close);

        popup.showAndWait();
    } catch (IOException ex) {
        Logger.getLogger(CurlyApp.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 7
Source File: NaviSelectDemo.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
/**
 * Select value example. Implement whatever technique you want to change value of the NaviSelect
 */
private void selectEmail(NaviSelect<Email> navi) {
	Stage dialog = new Stage(StageStyle.UTILITY);
	dialog.setTitle("Choose person");
	ListView<Email> listview = new ListView<>(FXCollections.observableArrayList(
		new Email("[email protected]", "John Doe"),
		new Email("[email protected]", "Jane Doe"),
		new Email("[email protected]", "Some Dude")
	));
	listview.setOnMouseClicked(event -> {
		Email item = listview.getSelectionModel().getSelectedItem();
		if (item != null) {
			navi.setValue(item);
			dialog.close();
		}
	});
	dialog.setScene(new Scene(listview));
	dialog.setWidth(navi.getWidth());
	dialog.initModality(Modality.APPLICATION_MODAL);
	dialog.setHeight(100);
	dialog.showAndWait();
}
 
Example 8
Source File: Login.java    From ChatRoomFX with MIT License 6 votes vote down vote up
@FXML
private void createAccount(MouseEvent evt){
    Stage stage=new Stage();
    stage.initStyle(StageStyle.TRANSPARENT);
    FXMLLoader fxmlLoader=new FXMLLoader(getClass().getResource("/lk/ijse/gdse41/publicChatClient/ui/fxml/CreateNewAccount.fxml"));
    try {
        Scene scene=new Scene(fxmlLoader.load());
        scene.setFill(Color.TRANSPARENT);
        CreateNewAccount accController=fxmlLoader.getController();
        accController.setController(controller);
        stage.setScene(scene);
        stage.showAndWait();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
 
Example 9
Source File: ConnectPanel.java    From MythRedisClient with Apache License 2.0 5 votes vote down vote up
/**
 * 显示连接属性面板.
 * @return 是否点击确认
 */
public boolean showConnectPanel(String poolId) {
    boolean ok = false;

    // 创建 FXMLLoader 对象
    FXMLLoader loader = new FXMLLoader();
    // 加载文件
    loader.setLocation(this.getClass().getResource("/views/ConnectLayout.fxml"));
    AnchorPane pane = null;
    try {
        pane = loader.load();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // 创建对话框
    Stage dialogStage = new Stage();
    dialogStage.setTitle("创建连接");
    dialogStage.initModality(Modality.WINDOW_MODAL);
    Scene scene = new Scene(pane);
    dialogStage.setScene(scene);


    connectController = loader.getController();
    connectController.setDialogStage(dialogStage);
    connectController.setPoolId(poolId);

    // 显示对话框, 并等待, 直到用户关闭
    dialogStage.showAndWait();

    ok = connectController.isOkChecked();

    return ok;
}
 
Example 10
Source File: ConfirmBox.java    From SmartCity-ParkingManagement with Apache License 2.0 5 votes vote down vote up
public boolean display(final String title, final String message) {
	final Stage window = new Stage();
	window.initModality(Modality.APPLICATION_MODAL);
	window.setTitle(title);
	window.setMinWidth(250);
	window.setMinHeight(150);
	window.getIcons().add(new Image(getClass().getResourceAsStream("Smart_parking_icon.png")));

	final Label label = new Label();
	label.setText(message);

	yesButton = new Button("Yes");
	yesButton.setOnAction(λ -> {

		answer = true;
		window.close();
	});

	noButton = new Button("No");
	noButton.setOnAction(λ -> {
		answer = false;
		window.close();
	});

	final VBox layout = new VBox();
	layout.getChildren().addAll(label, noButton, yesButton);
	layout.setAlignment(Pos.CENTER);
	final Scene scene = new Scene(layout);
	scene.getStylesheets().add(getClass().getResource("mainStyle.css").toExternalForm());
	window.setScene(scene);
	window.showAndWait();

	return answer;
}
 
Example 11
Source File: RealMain.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
/**
 * Called when no MPF is given on command line while running Marathon in GUI
 * mode. Pops up a dialog for selecting a MPF.
 *
 * @param arg
 *            , the MPF given on command line, null if none given
 * @return MPF selected by the user. Can be null.
 */
private static String getProjectDirectory(final String arg) {
    if (arg != null && !ProjectFile.isValidProjectDirectory(new File(arg))) {
        argProcessor.help("`" + arg + "`Please provide a Marathon project folder.");
    }
    if (arg != null) {
        return arg;
    }
    List<String> selectedProjects = new ArrayList<>();
    ObservableList<ProjectInfo> projectList = FXCollections.observableArrayList();
    List<List<String>> frameworks = Arrays.asList(Arrays.asList("Java/Swing Project", Constants.FRAMEWORK_SWING),
            Arrays.asList("Java/FX Project", Constants.FRAMEWORK_FX),
            Arrays.asList("Web Application Project", Constants.FRAMEWORK_WEB));
    ProjectSelection selection = new ProjectSelection(projectList, frameworks) {
        @Override
        protected void onSelect(ProjectInfo selected) {
            super.onSelect(selected);
            selectedProjects.add(selected.getFolder());
            dispose();
        }
    };
    Stage stage = selection.getStage();
    selection.setNewProjectHandler(new NewProjectHandler(stage));
    selection.setEditProjectHandler(new EditProjectHandler(stage));
    stage.showAndWait();
    if (selectedProjects.size() == 0) {
        return null;
    }
    Preferences.resetInstance();
    return selectedProjects.get(0);
}
 
Example 12
Source File: ModalDialog.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public T show(Window parent) {
    Stage stage = getStage();
    stage.initModality(Modality.APPLICATION_MODAL);
    focusOnFirstControl(stage.getScene().getRoot());
    stage.showAndWait();
    return getReturnValue();
}
 
Example 13
Source File: DisplayWindow.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void onInsertChecklist() {
    String checklistDir = System.getProperty(Constants.PROP_CHECKLIST_DIR);
    File dir = new File(checklistDir);
    CheckListForm checkListInfo = new CheckListForm(dir, true);
    MarathonCheckListStage checklistStage = new MarathonCheckListStage(checkListInfo);
    checklistStage.setInsertCheckListHandler(new IInsertCheckListHandler() {
        @Override
        public boolean insert(CheckListElement selectedItem) {
            insertChecklist(selectedItem.getFile().getName());
            return true;
        }
    });
    Stage stage = checklistStage.getStage();
    stage.showAndWait();
}
 
Example 14
Source File: MainController.java    From cate with MIT License 5 votes vote down vote up
private boolean showTxDetailsDialog(WalletTransaction item) {
    try {
        final Stage dialog = TransactionDetailsDialog.build(resources, item);
        dialog.showAndWait();
        return true;
    } catch (IOException e) {
        logger.error(resources.getString("alert.txDetailsError"), e);
        Alert alert = new Alert(Alert.AlertType.ERROR, resources.getString("alert.txDetailsError")
            + e.getMessage());
        alert.setTitle(resources.getString("internalError.title"));
        alert.showAndWait();
    }
    return false;
}
 
Example 15
Source File: MusicPlayer.java    From MusicPlayer with MIT License 5 votes vote down vote up
private static void createLibraryXML() {
    try {
        FXMLLoader loader = new FXMLLoader(MusicPlayer.class.getResource(Resources.FXML + "ImportMusicDialog.fxml"));
        BorderPane importView = loader.load();

        // Create the dialog Stage.
        Stage dialogStage = new Stage();
        dialogStage.setTitle("Music Player Configuration");
        // Forces user to focus on dialog.
        dialogStage.initModality(Modality.WINDOW_MODAL);
        // Sets minimal decorations for dialog.
        dialogStage.initStyle(StageStyle.UTILITY);
        // Prevents the alert from being re-sizable.
        dialogStage.setResizable(false);
        dialogStage.initOwner(stage);

        // Sets the import music dialog scene in the stage.
        dialogStage.setScene(new Scene(importView));

        // Set the dialog into the controller.
        ImportMusicDialogController controller = loader.getController();
        controller.setDialogStage(dialogStage);

        // Show the dialog and wait until the user closes it.
        dialogStage.showAndWait();

        // Checks if the music was imported successfully. Closes the application otherwise.
        boolean musicImported = controller.isMusicImported();
        if (!musicImported) {
            System.exit(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: HugoPane.java    From Lipi with MIT License 5 votes vote down vote up
@FXML
private void onOpenAdvancedConfig() {
    Stage tomlConfigEditorStage = new Stage();

    tomlConfigEditorStage.setTitle("Site Preference Editor (TOML)");
    tomlConfigEditorStage.setScene(new Scene(new TomlConfigEditor(hugoSiteConfigFilePath)));

    tomlConfigEditorStage.showAndWait();
}
 
Example 17
Source File: AboutHandler.java    From VocabHunter with Apache License 2.0 4 votes vote down vote up
private void setupStage(final Stage stage, final Parent root) {
    stage.initModality(Modality.APPLICATION_MODAL);
    stage.initStyle(StageStyle.UNDECORATED);
    stage.setScene(new Scene(root));
    stage.showAndWait();
}
 
Example 18
Source File: CreateNewAccount.java    From ChatRoomFX with MIT License 4 votes vote down vote up
private void showConfirmation(){
        Stage stage=new Stage();
        VBox box=new VBox();

        box.setId("root");
        box.setSpacing(10);
        box.setPadding(new Insets(8));

        HBox titleBox=new HBox();
        titleBox.setPadding(new Insets(8));
        titleBox.setPrefWidth(box.getPrefWidth());
        titleBox.setAlignment(Pos.CENTER);
        Label title=new Label("Set Password");
        title.setId("title");
        titleBox.getChildren().add(title);

        box.getChildren().add(titleBox);

        HBox containerBox=new HBox();
        containerBox.setPrefWidth(box.getPrefWidth());

        VBox lblBox=new VBox();
        lblBox.setSpacing(8);
        lblBox.setAlignment(Pos.CENTER_LEFT);
//        lblBox.setPrefWidth(box.getPrefWidth()/3);

        Label lblPass=new Label("Password");
        lblPass.getStyleClass().add("label-info");
        Label lblConPass=new Label("Confirm Password");
        lblConPass.getStyleClass().add("label-info");

        lblBox.getChildren().addAll(lblPass,lblConPass);

        containerBox.getChildren().add(lblBox);

        VBox txtBox=new VBox();
        txtBox.setSpacing(8);

        PasswordField txtPass=new PasswordField();
        txtPass.setPrefWidth(100);

        PasswordField txtConPass=new PasswordField();
        txtPass.setPrefWidth(100);

        txtBox.setPadding(new Insets(8));

        txtBox.getChildren().addAll(txtPass,txtConPass);

        containerBox.getChildren().add(txtBox);

        box.getChildren().add(containerBox);

        Button button=new Button("Confirm");
        button.setId("btnCreate");

        button.setOnAction(e->{
            if(!txtPass.getText().equals(txtConPass.getText())){
                System.out.println("Password mismatch!");
            }else{
                password=txtPass.getText();
                System.out.println("Success!");
                ((Stage)txtPass.getScene().getWindow()).close();
            }
        });

        HBox buttonBox=new HBox();
        buttonBox.setPadding(new Insets(10));
        buttonBox.setPrefWidth(box.getPrefWidth());
        buttonBox.setAlignment(Pos.CENTER_RIGHT);
        buttonBox.getChildren().add(button);

        box.getChildren().add(buttonBox);

        Scene scene=new Scene(box);
        scene.getStylesheets().add(getClass().getResource("/lk/ijse/gdse41/publicChatClient/ui/util/css/Login.css").toExternalForm());
        stage.setScene(scene);
        stage.showAndWait();
    }
 
Example 19
Source File: MainController.java    From KorgPackage with GNU General Public License v3.0 4 votes vote down vote up
public void editChunkAction() {
    Chunk chunk = (Chunk) chunksListView.getSelectionModel().getSelectedItem();
    if (chunk != null) {
        String view;
        switch (chunk.getId()) {
            case Chunk.HEADER:
                view = "HeaderEditWindow.fxml";
                break;
            case Chunk.UPDATE_KERNEL:
            case Chunk.UPDATE_RAMDISK:
            case Chunk.UPDATE_INSTALLER_APP:
            case Chunk.UPDATE_INSTALLER_APP_CONFIG:
            case Chunk.SERVICE_KERNEL:
            case Chunk.SERVICE_RAMDISK:
            case Chunk.SERVICE_APP:
            case Chunk.SERVICE_APP_CONFIG:
            case Chunk.UPDATE_LAUNCHER_APP:
            case Chunk.UPDATE_LAUNCHER_APP_CONFIG:
            case Chunk.MLO:
            case Chunk.UBOOT:
            case Chunk.USER_KERNEL:
                view = "SystemFileEditWindow.fxml";
                break;
            case Chunk.INSTALLER_SCRIPT:
                view = "InstallerScriptEditWindow.fxml";
                break;
            case Chunk.DIRECTORY:
                view = "DirectoryEditWindow.fxml";
                break;
            case Chunk.FILE:
                view = "FileEditWindow.fxml";
                break;
            case Chunk.ROOT_FS:
                view = "RootFSEditWindow.fxml";
                break;
            default:
                return;
        }

        try {
            FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(view));
            Parent root = loader.load();
            ChunkEditController controller = loader.getController();
            Stage editWindow = new Stage();
            controller.setup(editWindow, chunk);
            editWindow.setScene(new Scene(root));
            editWindow.setResizable(false);
            editWindow.initModality(Modality.APPLICATION_MODAL);
            editWindow.showAndWait();
            refreshList();
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
    }
}
 
Example 20
Source File: MenuController.java    From zest-writer with GNU General Public License v3.0 3 votes vote down vote up
@FXML private void handleOptionsButtonAction(ActionEvent event){
    FXMLLoader loader = new CustomFXMLLoader(MainApp.class.getResource("fxml/OptionsDialog.fxml"));

    Stage dialogStage = new CustomStage(loader, Configuration.getBundle().getString("ui.menu.options"));
    dialogStage.setResizable(false);


    OptionsDialog optionsController = loader.getController();
    optionsController.setWindow(dialogStage);

    dialogStage.showAndWait();
    mainApp.getIndex().refreshRecentProject();
}