下面列出了javafx.scene.control.Alert#setTitle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void salir(ActionEvent actionEvent) {
Stage stage = (Stage) btn_salir.getScene().getWindow();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("sample.fxml"));
Parent root = null;
try {
root = fxmlLoader.load();
} catch (Exception e) {
Alert alerta = new Alert(Alert.AlertType.ERROR);
alerta.setTitle("Error de Aplicación");
alerta.setContentText("Llama al lapecillo de sistemas.");
alerta.showAndWait();
Platform.exit();
}
FadeTransition ft = new FadeTransition(Duration.millis(1500), root);
ft.setFromValue(0.0);
ft.setToValue(1.0);
ft.play();
//? controller = fxmlLoader.<?>getController();
//controller.setConteo(conteo);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
protected void afterSuccess() {
if (statisticCheck.isSelected()) {
startStatistic();
} else {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("MyBox");
alert.setContentText(message("EpidemicReportStatistic"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonOK = new ButtonType(AppVariables.message("OK"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonOK, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonOK) {
startStatistic();
}
}
}
public void salir(MouseEvent mouseEvent) {
Stage stage = (Stage) salir.getScene().getWindow();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Login.fxml"));
Parent root = null;
try {
root = fxmlLoader.load();
} catch (Exception e) {
Alert alerta = new Alert(Alert.AlertType.ERROR);
alerta.setTitle("Error de Aplicación");
alerta.setContentText("Llama al lapecillo de sistemas.");
alerta.showAndWait();
Platform.exit();
}
FadeTransition ft = new FadeTransition(Duration.millis(1500), root);
ft.setFromValue(0.0);
ft.setToValue(1.0);
ft.play();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
@Override
public boolean checkBeforeNextAction() {
if (fileChanged == null || !fileChanged.getValue()) {
return true;
} else {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVariables.message("NeedSaveBeforeAction"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVariables.message("Save"));
ButtonType buttonNotSave = new ButtonType(AppVariables.message("NotSave"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonSave, buttonNotSave, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonSave) {
saveAction();
return false;
} else {
return result.get() == buttonNotSave;
}
}
}
private void helpAbout() {
String version = null;
Package pkg = this.getClass().getPackage();
if (pkg != null)
version = pkg.getImplementationVersion();
if (version == null)
version = "(dev)";
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle(Messages.get("MainWindow.about.title"));
alert.setHeaderText(Messages.get("MainWindow.about.headerText"));
alert.setContentText(Messages.get("MainWindow.about.contentText", version));
alert.setGraphic(new ImageView(new Image("org/markdownwriterfx/markdownwriterfx32.png")));
alert.initOwner(getScene().getWindow());
alert.getDialogPane().setPrefWidth(420);
alert.showAndWait();
}
public void atras(MouseEvent mouseEvent) {
Stage stage = (Stage) atras.getScene().getWindow();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("Resumen.fxml"));
Parent root = null;
try {
root = fxmlLoader.load();
} catch (Exception e) {
Alert alerta = new Alert(Alert.AlertType.ERROR);
alerta.setTitle("Error de Aplicación");
alerta.setContentText("Llama al lapecillo de sistemas.");
alerta.showAndWait();
Platform.exit();
}
FadeTransition ft = new FadeTransition(Duration.millis(1500), root);
ft.setFromValue(0.0);
ft.setToValue(1.0);
ft.play();
Resumen controller = fxmlLoader.<Resumen>getController();
controller.setCuenta();
controller.setSaldo();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/** Show info dialog */
private void showInfo()
{
final Alert dlg = new Alert(AlertType.INFORMATION);
dlg.setTitle(Messages.DockInfo);
// No DialogPane 'header', all info is in the 'content'
dlg.setHeaderText("");
final StringBuilder info = new StringBuilder();
fillInformation(info);
final TextArea content = new TextArea(info.toString());
content.setEditable(false);
content.setPrefSize(300, 100);
content.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
dlg.getDialogPane().setContent(content);
DialogHelper.positionDialog(dlg, name_tab, 0, 0);
dlg.setResizable(true);
dlg.showAndWait();
}
@Override
public boolean checkBeforeNextAction() {
if (!imageLoaded.get() || !imageUpdated.get()) {
return true;
}
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVariables.message("ImageChanged"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSave = new ButtonType(AppVariables.message("Save"));
ButtonType buttonSaveAs = new ButtonType(AppVariables.message("SaveAs"));
ButtonType buttonNotSave = new ButtonType(AppVariables.message("NotSave"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonSave, buttonSaveAs, buttonNotSave, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonSave) {
saveAction();
return true;
} else if (result.get() == buttonNotSave) {
return true;
} else if (result.get() == buttonSaveAs) {
saveAsAction();
return true;
} else {
return false;
}
}
@FXML
private void doChooser(final ActionEvent actionEvent)
{
DirectoryChooser directoryChooser = new DirectoryChooser();
String modelDirectory = model.directoryProperty().getValue();
if (!modelDirectory.isBlank())
{
directoryChooser.setInitialDirectory(new File(model.directoryProperty().getValue()));
}
File dir = directoryChooser.showDialog(optionsPathDialogScene.getWindow());
if (dir != null)
{
if (dir.listFiles().length > 0)
{
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Directory Not Empty");
alert.setContentText("The folder " + dir.getAbsolutePath() + " is not empty.\n"
+ "All ini files in this directory may be overwritten. " + "Are you sure?");
Optional<ButtonType> buttonType = alert.showAndWait();
buttonType.ifPresent(option -> {
if (option != ButtonType.YES)
{
return;
}
});
}
model.directoryProperty().setValue(dir.getAbsolutePath());
}
}
public boolean deleteFile(File sfile) {
if (sfile == null) {
return false;
}
if (deleteConfirmCheck != null && deleteConfirmCheck.isSelected()) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(getMyStage().getTitle());
alert.setContentText(AppVariables.message("SureDelete"));
alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
ButtonType buttonSure = new ButtonType(AppVariables.message("Sure"));
ButtonType buttonCancel = new ButtonType(AppVariables.message("Cancel"));
alert.getButtonTypes().setAll(buttonSure, buttonCancel);
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
stage.setAlwaysOnTop(true);
stage.toFront();
Optional<ButtonType> result = alert.showAndWait();
if (result.get() != buttonSure) {
return false;
}
}
if (sfile.delete()) {
popSuccessful();
return true;
} else {
popFailed();
return false;
}
}
/**
* Shows an alert dialog with an error message.
* Blocks until dialog closed.
*
* @param title of dialog
* @param message of error
*/
private void showErrorAlert(String title, String message) {
Alert dlg = DialogUtils.createAlert(AlertType.ERROR);
dlg.setTitle("Error - Initialization");
dlg.setHeaderText(title);
dlg.setContentText(message);
dlg.showAndWait();
}
private void displayMessage(String msg) {
logger.info(msg);
final Alert alert = new Alert(Alert.AlertType.ERROR);
alert.initStyle(StageStyle.UTILITY);
alert.setTitle("Information");
alert.setHeaderText("Error");
alert.setContentText(msg);
alert.showAndWait();
}
private void showAlert(ProcessInterruptedException e) {
Alert alert = new Alert(Alert.AlertType.ERROR);
ResourceBundle resources = getResourceBundle();
alert.setTitle(resources.getString("exception_alert.title"));
alert.setHeaderText(resources.getString("exception_alert.header"));
alert.setContentText(e.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String exceptionText = sw.toString();
Label stackTraceLabel = new Label(resources.getString("exception_alert.label"));
TextArea stackTraceTextArea = new TextArea(exceptionText);
stackTraceTextArea.setEditable(false);
stackTraceTextArea.setWrapText(true);
GridPane.setVgrow(stackTraceTextArea, Priority.ALWAYS);
GridPane.setHgrow(stackTraceTextArea, Priority.ALWAYS);
GridPane expandableContent = new GridPane();
expandableContent.setPrefSize(400, 400);
expandableContent.setMaxWidth(Double.MAX_VALUE);
expandableContent.add(stackTraceLabel, 0, 0);
expandableContent.add(stackTraceTextArea, 0, 1);
alert.getDialogPane().setExpandableContent(expandableContent);
// Dirty Linux only fix...
// Expandable zones cause the dialog not to resize correctly
if (System.getProperty("os.name").matches(".*[Ll]inux.*")) {
alert.getDialogPane().setPrefSize(600, 400);
alert.setResizable(true);
alert.getDialogPane().setExpanded(true);
}
alert.showAndWait();
}
@FXML
private void doChooser(final ActionEvent actionEvent)
{
DirectoryChooser directoryChooser = new DirectoryChooser();
String modelDirectory = model.directoryProperty().getValue();
if (!modelDirectory.isBlank())
{
directoryChooser.setInitialDirectory(new File(model.directoryProperty().getValue()));
}
File dir = directoryChooser.showDialog(optionsPathDialogScene.getWindow());
if (dir != null)
{
if (dir.listFiles().length > 0)
{
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Directory Not Empty");
alert.setContentText("The folder " + dir.getAbsolutePath() + " is not empty.\n"
+ "All ini files in this directory may be overwritten. " + "Are you sure?");
Optional<ButtonType> buttonType = alert.showAndWait();
buttonType.ifPresent(option -> {
if (option != ButtonType.YES)
{
return;
}
});
}
model.directoryProperty().setValue(dir.getAbsolutePath());
}
}
/**
* 判断输入的是否为数字.
* @return true为数字
*/
private boolean isNum() {
boolean ok = false;
String input = valueText.getText();
try {
Double.parseDouble(input);
ok = true;
} catch (Exception e) {
Alert alert = MyAlert.getInstance(Alert.AlertType.ERROR);
alert.setTitle("错误");
alert.setContentText("请输入数字");
alert.showAndWait();
}
return ok;
}
public void createAlert(String text) {
//Stage stage = new Stage();
stage.getIcons().add(new Image(this.getClass().getResource("/icons/lander_hab.svg").toString()));
String header = null;
//String text = null;
header = "Multiplayer Host Server";
//System.out.println("confirm dialog pop up.");
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.initOwner(stage);
alert.setTitle("Mars Simulation Project");
alert.setHeaderText(header);
alert.setContentText(text);
alert.initModality(Modality.APPLICATION_MODAL);
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.YES){
if (multiplayerServer != null) {
// TODO: fix the loading problem for server mode
multiplayerServer.setServerStopped(true);
}
notificationTimer.cancel();
Platform.exit();
tray.remove(trayIcon);
System.exit(0);
}
//else {
//}
}
public static void showException(Throwable throwable) {
throwable.printStackTrace();
Alert information = new Alert(Alert.AlertType.ERROR);
information.setTitle(throwable.getClass().getSimpleName());
information.setHeaderText(throwable.getMessage());
information.showAndWait();
}
public static void showErrorDialog(String title, String content) {
Alert dialog = new Alert(Alert.AlertType.ERROR);
dialog.setTitle(title);
dialog.setHeaderText(null);
dialog.setResizable(true);
dialog.setContentText(content);
dialog.showAndWait();
}
public boolean numbersOnly(TextField txt) {
if (txt.getText().matches("[0-9]+")) {
return true;
} else {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Student Registration");
alert.setHeaderText(null);
alert.setContentText("Invalid Input Type..!");
alert.showAndWait();
return false;
}
}
@FXML
public void disconnect() {
if( !connected.get() ) {
if( logger.isWarnEnabled() ) {
logger.warn("client not connected; skipping disconnect");
}
return;
}
if( logger.isDebugEnabled() ) {
logger.debug("[DISCONNECT]");
}
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
updateMessage("Disconnecting");
updateProgress(0.1d, 1.0d);
channel.close().sync();
updateMessage("Closing group");
updateProgress(0.5d, 1.0d);
group.shutdownGracefully().sync();
return null;
}
@Override
protected void succeeded() {
connected.set(false);
}
@Override
protected void failed() {
connected.set(false);
Throwable t = getException();
logger.error( "client disconnect error", t );
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Client");
alert.setHeaderText( t.getClass().getName() );
alert.setContentText( t.getMessage() );
alert.showAndWait();
}
};
hboxStatus.visibleProperty().bind( task.runningProperty() );
lblStatus.textProperty().bind( task.messageProperty() );
piStatus.progressProperty().bind(task.progressProperty());
new Thread(task).start();
}