public void showEDResult(List<String> path) { // intialize alert/dialog to display edit distance result Alert alert = new Alert(AlertType.INFORMATION); alert.setTitle("Result"); alert.setHeaderText("Word Path : "); alert.initModality(Modality.NONE); alert.setResizable(true); // create layout for content VBox box = new VBox(); HBox midBox = new HBox(); box.setPadding(new Insets(35, 0, 35, 0)); box.setSpacing(35); midBox.setSpacing(15); Label pathLabel = new Label(); Label numStepsLabel = new Label("Number of steps : "); Label numSteps = new Label(); Font font = new Font(14); pathLabel.setFont(font); numStepsLabel.setFont(font); numSteps.setFont(Font.font(font.getFamily(), FontWeight.BOLD, 14)); midBox.getChildren().add(numStepsLabel); midBox.getChildren().add(numSteps); midBox.setAlignment(Pos.CENTER); box.getChildren().add(pathLabel); box.getChildren().add(midBox); box.setAlignment(Pos.CENTER); alert.getDialogPane().setPrefWidth(300); // check for path if (path != null) { numSteps.setText(Integer.toString(path.size() - 1)); pathLabel.setText(String.join(" -> ", path)); Text text = new Text(pathLabel.getText()); text.setFont(font); if (text.getLayoutBounds().getWidth() > 200) { alert.getDialogPane().setPrefWidth(text.getLayoutBounds().getWidth() + 100); } } // no path found else { pathLabel.setText("No Path Found."); numSteps.setText("N/A"); } // set content and styling alert.getDialogPane().setContent(box); alert .getDialogPane() .getStylesheets() .add(getClass().getResource("application.css").toExternalForm()); alert.getDialogPane().getStyleClass().add("myDialog"); alert.showAndWait(); }
/** * * Displays an alert box * * @param title The text to set the Alert box to * @param headerText The header text to set the Alert box to * @param contentText The content text to set the Alert box to */ public static void show(String title, String headerText, String contentText) { Alert alert = new Alert(Alert.AlertType.INFORMATION); alert.setTitle(title); alert.setHeaderText(headerText); alert.setContentText(contentText); alert.initModality(Modality.APPLICATION_MODAL); alert.initStyle(StageStyle.UTILITY); alert.showAndWait(); }