build JavaFX Dialog - Java JavaFX

Java examples for JavaFX:Dialog

Description

build JavaFX Dialog

Demo Code

/*******************************************************************************
     * Copyright (c) 2016 Sebastian Stenzel and others.
     * This file is licensed under the terms of the MIT license.
     * See the LICENSE.txt file for more info.
     *//from  w w  w. ja  va 2  s  .c  o m
     * Contributors:
     *     Jean-No?l Charon - initial API and implementation
     *******************************************************************************/
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.text.Text;

public class Main{
    private static Alert buildDialog(String title, String header, String content, Alert.AlertType type, ButtonType defaultButton) {
   Text contentText = new Text(content);
   contentText.setWrappingWidth(360.0);

   Alert alert = new Alert(type);
   alert.setTitle(title);
   alert.setHeaderText(header);
   alert.getDialogPane().setContent(contentText);

   alert.getDialogPane().getButtonTypes().stream().forEach(buttonType -> {
      Button btn = (Button) alert.getDialogPane().lookupButton(buttonType);
      btn.setDefaultButton(buttonType.equals(defaultButton));
   });

   return alert;
}
}

Related Tutorials