FULL PRODUCT VERSION :
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The documentation for javafx.scene.control.Dialog indicates that when a dialog is abnormally closed, the result should be set to the first ButtonType with ButtonData that is either:
1) ButtonData.CANCEL_CLOSE, or
2) ButtonData.isCancelButton() is true.
However, testing reveals that abnormally closing a dialog follows this behavior only when the Result property is set to null. If that property is not null, abnormally closing the dialog returns the value of that property when the dialog was shown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code provided. Select the "Yes" button the first time the dialog is shown. The second time the dialog is shown, click the small "x" in the upper-right of the dialog to abnormally close it.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The sample application should print the following to the console:
Yes
No or Closed
ACTUAL -
The sample application actually prints the following to the console:
Yes
Yes
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package myPackage;
import java.util.Optional;
import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(final String[] args) {
launch();
}
private static boolean isYes(final Optional<ButtonType> result) {
return (result.isPresent() && result.get().getButtonData() == ButtonData.YES);
}
@Override
public void start(Stage primaryStage) throws Exception {
final Alert alert = new Alert(AlertType.CONFIRMATION,
"This is a test", ButtonType.NO, ButtonType.YES);
System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add the following immediately after creating a javafx.scene.control.Dialog:
Dialog dialog = new Alert(...);
dialog.setOnShowing(event -> dialog.setResult(null));
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
The documentation for javafx.scene.control.Dialog indicates that when a dialog is abnormally closed, the result should be set to the first ButtonType with ButtonData that is either:
1) ButtonData.CANCEL_CLOSE, or
2) ButtonData.isCancelButton() is true.
However, testing reveals that abnormally closing a dialog follows this behavior only when the Result property is set to null. If that property is not null, abnormally closing the dialog returns the value of that property when the dialog was shown.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the source code provided. Select the "Yes" button the first time the dialog is shown. The second time the dialog is shown, click the small "x" in the upper-right of the dialog to abnormally close it.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The sample application should print the following to the console:
Yes
No or Closed
ACTUAL -
The sample application actually prints the following to the console:
Yes
Yes
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package myPackage;
import java.util.Optional;
import javafx.application.Application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(final String[] args) {
launch();
}
private static boolean isYes(final Optional<ButtonType> result) {
return (result.isPresent() && result.get().getButtonData() == ButtonData.YES);
}
@Override
public void start(Stage primaryStage) throws Exception {
final Alert alert = new Alert(AlertType.CONFIRMATION,
"This is a test", ButtonType.NO, ButtonType.YES);
System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
System.out.println(isYes(alert.showAndWait()) ? "Yes" : "No or Closed");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add the following immediately after creating a javafx.scene.control.Dialog:
Dialog dialog = new Alert(...);
dialog.setOnShowing(event -> dialog.setResult(null));