Java examples for JavaFX:Dialog
Build a javafx.scene.control.Dialog Dialog object.
/*/* w ww . jav a 2 s . com*/ * Copyright 2015 Thierry Wasylczenko * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import javafx.scene.Node; import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.stage.Stage; import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.logging.Level; import java.util.logging.Logger; public class Main{ private static final Logger LOGGER = Logger .getLogger(DialogHelper.class.getName()); /** * Build a {@link javafx.scene.control.Dialog Dialog} object. This method ensures the dialog is created in a JavaFX * application thread. If the dialog can not be created then {@code null} is returned. * @param title The title of the Dialog * @param content The content of the Dialog * @param buttons The type of buttons the Dialog will contain. * @return A well created Dialog or {@code null} if an error occurred during the creation of the Dialog. */ private static Dialog buildDialog(final String title, final Node content, final ButtonType ... buttons) { final FutureTask<Dialog> future = new FutureTask<>(() -> { final Dialog dialog = new Dialog(); dialog.setGraphic(null); dialog.setHeaderText(null); dialog.setTitle(title); dialog.getDialogPane().getButtonTypes().addAll(buttons); dialog.getDialogPane().setContent(content); dialog.getDialogPane().getStylesheets().add("/com/twasyl/slideshowfx/css/Default.css"); return dialog; }); PlatformHelper.run(future); Dialog dialog = null; try { dialog = future.get(); } catch (InterruptedException | ExecutionException e) { LOGGER.log(Level.SEVERE, "Can not build a Dialog", e); } return dialog; } }