Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Fixed a problem with the close button in some popups can't be used to…
Browse files Browse the repository at this point in the history
… close the popup
  • Loading branch information
Stekeblad committed Jun 2, 2021
1 parent 05f8c0a commit 1d2414c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javafx.application.Platform;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
Expand Down Expand Up @@ -58,7 +59,7 @@ private static GridPane makeLongMsgPane(String longMsg, boolean wrapText) {
textArea.setEditable(false);
textArea.setWrapText(wrapText);
Button closeButton = new Button("Close");
closeButton.setCancelButton(true);
closeButton.setId("btnClose");

GridPane pane = new GridPane();
GridPane.setMargin(textArea, new Insets(3, 0, 0, 0));
Expand All @@ -78,6 +79,17 @@ private static GridPane makeLongMsgPane(String longMsg, boolean wrapText) {
private static void paneToWindow(Pane pane, String header) {
Scene alertDialog = new Scene(pane);
Stage stage = new Stage();

// Try checking for a close button on the pane and bind it to closing the stage
Node closeButtonNode = alertDialog.lookup("#btnClose");
if (closeButtonNode instanceof Button) {
Button closeButton = (Button) closeButtonNode;
closeButton.setOnMouseClicked((event -> {
event.consume();
stage.close();
}));
}

stage.initModality(Modality.APPLICATION_MODAL);
stage.setScene(alertDialog);
stage.setTitle(header);
Expand Down

0 comments on commit 1d2414c

Please sign in to comment.