Bug ID: JDK-8131151 -- updated test code
Paul Furbacher
pfurbacher at mac.com
Tue Jul 14 19:04:40 UTC 2015
Because of the move to JBS, we commoners can no longer comment or add more info on bug reports we submit. It seems we are stuck with bothering this list with such stuff.
For Bug ID: JDK-8131151 : "Pressing ESC in a nested alert closes self and parent alert”, I decided to do some more investigating — is this just something that happens with file choosers? So, I extended the test code and discovered it is not limited to such circumstances.
Here’s the updated code which I hope provides a pretty thorough look into the problem but which I am not able to provide as an update on JBS. Sorry to make more work for someone else.
****
import javafx.application.Application;
import javafx.application.Platform;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
/**
* As of at least JDK 1.8.0_60 early releases (maybe earlier, e.g. 1.8.0_40), if you launch a dialog
* (e.g., file/dir chooser from a JavaFX Alert, and the user presses ESC to close the dialog, the
* alert will also close.
*
* In this demo, I show that the behavior occurs in any type of child alert (or file browser) which
* presents an ButtonType.CANCEL button. It does not occur if such a button is absent.
*
* This is unexpected behavior.
*
* @author Paul Furbacher
*
*/
public class DemoApp extends Application {
private static final String VBOX_STYLE = "-fx-padding: 12px; -fx-alignment: center";
@Override
public void start(Stage primaryStage) throws Exception {
VBox vbox = new VBox(16);
vbox.setStyle(VBOX_STYLE);
Label label = new Label("Press button to launch dialog");
Button button = new Button("Save ...");
button.setOnAction(ae -> {
createAndShowDirChooser();
});
vbox.getChildren().addAll(label, button);
primaryStage.setScene(new Scene(vbox));
primaryStage.sizeToScene();
primaryStage.show();
}
protected void createAndShowDirChooser() {
Alert alert = new Alert(AlertType.INFORMATION); // or try other types, such as
// AlertType.CONFIRMATION.
// Except for AlertType.NONE, they all exhibit the problem.
alert.setTitle("Demo Alert");
Button browseButton = new Button("Browse...");
browseButton.setOnAction(ae -> {
DirectoryChooser chooser = new DirectoryChooser();
chooser.showDialog(browseButton.getScene().getWindow());
});
VBox vbox = new VBox(16);
vbox.setStyle(VBOX_STYLE);
vbox.getChildren().addAll(
new Label("Press ESC in the directory chooser.\n\n"
+ "Unexpected result: this dialog will also close!\n\n"),
browseButton,
new Label("Test whether this also occurs with child 'Alert' dialogs of different types.\n\n"
+ "Yes, it does if a Cancel button is present."));
ObservableList<Node> children = vbox.getChildren();
for (AlertType alertType : AlertType.values()) {
Button childAlertButton = new Button("Child Alert (" + alertType.name() + ")");
childAlertButton.setOnAction(ae -> {
createAndShowChildAlert(alertType);
});
children.add(childAlertButton);
}
alert.getDialogPane().setContent(vbox);
Platform.runLater(() -> browseButton.requestFocus());
alert.showAndWait();
}
private void createAndShowChildAlert(AlertType alertType) {
Alert alert = new Alert(alertType);
alert.setTitle("Child Alert :: type = " + alertType.name());
alert.setContentText("Just press ESC to close.");
if (alertType.equals(AlertType.NONE)) {
alert.setContentText(alert.getContentText().concat(
"\n\n(Normally, AlertType.NONE has no buttons. We added one here "
+ "to demonstrate that it is the presence of a ButtonType.CANCEL button which prompts this buggy behavior."));
alert.getButtonTypes().add(ButtonType.CANCEL);
}
alert.showAndWait();
}
public static void main(String[] args) {
Application.launch(args);
}
}
****
Paul Furbacher
More information about the openjfx-dev
mailing list