grid.add(password, 1, 1); final Node loginButton = pane.lookupButton(authButtonType);
private static Alert setDefaultButton ( Alert alert, ButtonType defBtn ) { DialogPane pane = alert.getDialogPane(); for ( ButtonType t : alert.getButtonTypes() ) ( (Button) pane.lookupButton(t) ).setDefaultButton( t == defBtn ); return alert; }
@Override protected double computePrefWidth(double height) { boolean isDefault = true; double pw = 0; for (ButtonType buttonType : getDialogPane().getButtonTypes()) { Button button = (Button) getDialogPane().lookupButton(buttonType); double buttonPrefWidth = button.getGraphic().prefWidth(-1); if (isDefault) { pw = buttonPrefWidth; isDefault = false; } else { pw = Math.min(pw, buttonPrefWidth); } } return pw + gapSize; }
private void validateButton( ButtonType buttonType, BooleanSupplier condition) { Button btn = (Button)dialog.getDialogPane().lookupButton(buttonType); if ( btn != null ) { Node focusOwner = (btn.getScene() != null) ? btn.getScene().getFocusOwner() : null; btn.setDisable(condition.getAsBoolean()); if(focusOwner != null) { focusOwner.requestFocus(); } } }
Alert alert = new Alert(Alert.AlertType.WARNING, "I Warn You!", ButtonType.OK, ButtonType.CANCEL); DialogPane root = alert.getDialogPane(); Stage dialogStage = new Stage(StageStyle.UTILITY); for (ButtonType buttonType : root.getButtonTypes()) { ButtonBase button = (ButtonBase) root.lookupButton(buttonType); button.setOnAction(evt -> { root.setUserData(buttonType); dialogStage.close(); }); } // replace old scene root with placeholder to allow using root in other Scene root.getScene().setRoot(new Group()); root.setPadding(new Insets(10, 0, 10, 0)); Scene scene = new Scene(root); dialogStage.setScene(scene); dialogStage.initModality(Modality.APPLICATION_MODAL); dialogStage.setAlwaysOnTop(true); dialogStage.setResizable(false); dialogStage.showAndWait(); Optional<ButtonType> result = Optional.ofNullable((ButtonType) root.getUserData()); System.out.println("result: "+result.orElse(null));
@Override protected void addCustomButtons(final DialogPane dialogPane) { // add 'Calculate' button to button bar final ButtonType bTypeCalculate = new ButtonType(context.getResources().getString( "st.dlg.statistic.calculate.Action.text"), ButtonBar.ButtonData.OK_DONE); dialogPane.getButtonTypes().add(bTypeCalculate); final Button buttonCalculate = (Button) dialogPane.lookupButton(bTypeCalculate); // set action event filter for this custom button // => the event must be consumed, otherwise the dialog will be closed buttonCalculate.addEventFilter(ActionEvent.ACTION, (event) -> { event.consume(); onCalculate(event); }); }
dialogPane.setHeaderText("Processing file"); dialogPane.setContent(progressBar); dialogPane.lookupButton(ButtonType.OK).setDisable(true); Dialog dialog = new Dialog(); dialog.setDialogPane(dialogPane); dialogPane.lookupButton(ButtonType.OK).setDisable(false); progressBar.progressProperty().unbind(); progressBar.setProgress(1); dialogPane.lookupButton(ButtonType.OK).setDisable(false); progressBar.progressProperty().unbind(); progressBar.setProgress(0);
@Override protected double computePrefHeight(double width) { double ph = getDialogPane().getHeader() == null ? 0 : 10; for (ButtonType buttonType : getDialogPane().getButtonTypes()) { Button button = (Button) getDialogPane().lookupButton(buttonType); ph += button.prefHeight(width) + gapSize; } // TODO remove magic number return ph * 1.2; } };
/** * Shows a question dialog. * * @param message the message * @param defaultYes true if yes is the default button * @return true if yes, false if no */ public boolean showQuestionDialog(String message, boolean defaultYes) { Alert alert = new Alert(Alert.AlertType.CONFIRMATION); alert.setTitle(FxFxBundle.getString("QUESTION")); setAlertMessage(alert, message); alert.getButtonTypes().clear(); alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); Button noButton = (Button) alert.getDialogPane().lookupButton(ButtonType.NO); Button yesButton = (Button) alert.getDialogPane().lookupButton(ButtonType.YES); noButton.setDefaultButton(!defaultYes); yesButton.setDefaultButton(defaultYes); Optional<ButtonType> result = alert.showAndWait(); return result.isPresent() && result.get() == ButtonType.YES; }
public static <F> Optional<F> showAndWaitDialog(Window window, F parent, Function<String, F> folderCreator, Predicate<String> folderUnique) { Objects.requireNonNull(window); Objects.requireNonNull(parent); Objects.requireNonNull(folderCreator); Objects.requireNonNull(folderUnique); Dialog<F> dialog = new Dialog<>(); try { dialog.setTitle(RESOURCE_BUNDLE.getString("NewFolder")); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); NewFolderPane<F> newProjectPane = new NewFolderPane<>(folderCreator, folderUnique); newProjectPane.setPrefSize(350, 100); dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(newProjectPane.validatedProperty().not()); dialog.getDialogPane().setContent(newProjectPane); dialog.setResizable(true); dialog.initOwner(window); dialog.setResultConverter(buttonType -> buttonType == ButtonType.OK ? newProjectPane.createFolder() : null); return dialog.showAndWait(); } finally { dialog.close(); } } }
private void rename() { TreeItem<Object> item = contingencyTree.getSelectionModel().getSelectedItem(); Contingency contingency = (Contingency) item.getValue(); TextInputDialog dialog = new TextInputDialog(contingency.getId()); dialog.setTitle(RESOURCE_BUNDLE.getString("RenameContingency")); dialog.setHeaderText(null); dialog.setGraphic(null); dialog.setContentText(RESOURCE_BUNDLE.getString("Name")); TextField inputField = dialog.getEditor(); BooleanBinding isInvalid = Bindings.createBooleanBinding(() -> inputField.getText().equals(contingency.getId()) || inputField.getText().isEmpty(), inputField.textProperty()); dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(isInvalid); Optional<String> result = dialog.showAndWait(); result.ifPresent(newName -> { contingency.setId(newName); contingencyTree.refresh(); saved.set(false); }); }
Button loginButton = (Button) dialogPane.lookupButton(loginButtonType); loginButton.setOnAction(actionEvent -> { try {
final Button btOk = (Button) dlg.getDialogPane().lookupButton(ButtonType.OK); btOk.disableProperty().bind(validationSupport.invalidProperty());
Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); loginButton.setDisable(true);
private void updateGrid() { grid.getChildren().clear(); // add the message to the top of the dialog updateContentText(); // then build all the buttons int row = 1; for (final ButtonType buttonType : getDialogPane().getButtonTypes()) { if (buttonType == null) continue; final Button button = (Button)getDialogPane().lookupButton(buttonType); GridPane.setHgrow(button, Priority.ALWAYS); GridPane.setVgrow(button, Priority.ALWAYS); grid.add(button, 0, row++); } // // last button gets some extra padding (hacky) // GridPane.setMargin(buttons.get(buttons.size() - 1), new Insets(0,0,10,0)); getDialogPane().setContent(grid); getDialogPane().requestLayout(); }
public static Optional<String> showAndWaitDialog(AbstractNodeBase node, Predicate<String> nodeNameUnique) { Dialog<String> dialog = new Dialog<>(); try { dialog.setTitle(RESOURCE_BUNDLE.getString("RenameFile")); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); RenamePane renamePane = new RenamePane(node, nodeNameUnique); renamePane.setPrefSize(350, 100); dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(renamePane.validatedProperty().not()); dialog.getDialogPane().setContent(renamePane); dialog.setResizable(true); dialog.setResultConverter(buttonType -> buttonType == ButtonType.OK ? renamePane.getNameTextField().getText() : null); return dialog.showAndWait(); } finally { dialog.close(); } } }
dialog.getDialogPane().lookupButton(ButtonType.OK).disableProperty().bind(table.getSelectionModel().selectedItemProperty().isNull());
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); NodeChooser<N, F, D, T> nodeChooser = new NodeChooser<>(window, treeModel, appData, context, filter, openedProjectsList); Button button = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK); button.disableProperty().bind(nodeChooser.selectedNodeProperty().isNull()); nodeChooser.doubleClick().addListener((observable, oldValue, newValue) -> {
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL); Button button = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
Button okButton = (Button) dialogPane.lookupButton(ButtonType.OK); Platform.runLater(pathsField::requestFocus);