From 45841572546d8be551d07c3453c4fff6db9e5194 Mon Sep 17 00:00:00 2001 From: Rahman Usta Date: Sat, 18 Aug 2018 12:53:07 +0200 Subject: [PATCH] Show dialog allways in front --- .../java/com/kodedu/component/AlertDialog.java | 13 +++++++++++++ .../java/com/kodedu/component/AlertHelper.java | 1 + .../java/com/kodedu/component/DialogBuilder.java | 13 +++++++++++++ src/main/java/com/kodedu/component/TextDialog.java | 14 ++++++++++++++ .../com/kodedu/component/WindowModalAlert.java | 13 +++++++++++++ 5 files changed, 54 insertions(+) diff --git a/src/main/java/com/kodedu/component/AlertDialog.java b/src/main/java/com/kodedu/component/AlertDialog.java index 3ea8c0931..f92a87b70 100644 --- a/src/main/java/com/kodedu/component/AlertDialog.java +++ b/src/main/java/com/kodedu/component/AlertDialog.java @@ -2,7 +2,9 @@ import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.DialogPane; import javafx.stage.Modality; +import javafx.stage.Stage; /** * Created by Hakan on 3/9/2015. @@ -14,18 +16,29 @@ public AlertDialog() { super.setTitle("Warning"); super.initModality(Modality.WINDOW_MODAL); setDefaultIcon(super.getDialogPane()); + showAlwaysOnTop(this); } public AlertDialog(AlertType alertType) { super(alertType); super.initModality(Modality.WINDOW_MODAL); setDefaultIcon(super.getDialogPane()); + showAlwaysOnTop(this); } public AlertDialog(AlertType alertType, String contentText, ButtonType... buttons) { super(alertType, contentText, buttons); super.initModality(Modality.WINDOW_MODAL); setDefaultIcon(super.getDialogPane()); + showAlwaysOnTop(this); + } + + private static void showAlwaysOnTop(DialogPane dialogPane) { + ((Stage) dialogPane.getScene().getWindow()).setAlwaysOnTop(true); + } + + private static void showAlwaysOnTop(Alert alert) { + showAlwaysOnTop(alert.getDialogPane()); } } diff --git a/src/main/java/com/kodedu/component/AlertHelper.java b/src/main/java/com/kodedu/component/AlertHelper.java index f0803c43c..7a67917d6 100644 --- a/src/main/java/com/kodedu/component/AlertHelper.java +++ b/src/main/java/com/kodedu/component/AlertHelper.java @@ -9,6 +9,7 @@ import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.stage.Screen; +import javafx.stage.Stage; import java.nio.file.Path; import java.util.List; diff --git a/src/main/java/com/kodedu/component/DialogBuilder.java b/src/main/java/com/kodedu/component/DialogBuilder.java index bce34c4a2..a4ae0a226 100644 --- a/src/main/java/com/kodedu/component/DialogBuilder.java +++ b/src/main/java/com/kodedu/component/DialogBuilder.java @@ -1,6 +1,9 @@ package com.kodedu.component; +import javafx.scene.control.Alert; +import javafx.scene.control.DialogPane; import javafx.scene.control.TextField; +import javafx.stage.Stage; /** * Created by usta on 16.03.2015. @@ -13,6 +16,7 @@ public final class DialogBuilder extends TextDialog { public DialogBuilder(String content, String title) { super(content, title); + showAlwaysOnTop(getDialogPane()); } public static DialogBuilder newFileDialog() { @@ -40,4 +44,13 @@ public static DialogBuilder newJumpLineDialog() { editor.requestFocus(); return dialog; } + + private static void showAlwaysOnTop(DialogPane dialogPane) { + ((Stage) dialogPane.getScene().getWindow()).setAlwaysOnTop(true); + } + + private static void showAlwaysOnTop(Alert alert) { + showAlwaysOnTop(alert.getDialogPane()); + } + } diff --git a/src/main/java/com/kodedu/component/TextDialog.java b/src/main/java/com/kodedu/component/TextDialog.java index f5e1bb737..e44878262 100644 --- a/src/main/java/com/kodedu/component/TextDialog.java +++ b/src/main/java/com/kodedu/component/TextDialog.java @@ -1,7 +1,10 @@ package com.kodedu.component; +import javafx.scene.control.Alert; +import javafx.scene.control.DialogPane; import javafx.scene.control.TextInputDialog; import javafx.scene.control.Tooltip; +import javafx.stage.Stage; /** * Created by Hakan on 4/1/2015. @@ -9,16 +12,19 @@ public class TextDialog extends TextInputDialog implements DefenderDialog { public TextDialog() { + showAlwaysOnTop(super.getDialogPane()); } public TextDialog(String defaultValue) { super(defaultValue); + showAlwaysOnTop(super.getDialogPane()); } public TextDialog(String contentText, String title) { super.setContentText(contentText); super.setTitle(title); setDefaultIcon(super.getDialogPane()); + showAlwaysOnTop(super.getDialogPane()); } public void setKeyReleaseEvent(String regex) { @@ -37,4 +43,12 @@ public void setToolTip(String tip) { Tooltip.install(super.getEditor(), new Tooltip(tip)); } + private static void showAlwaysOnTop(DialogPane dialogPane) { + ((Stage) dialogPane.getScene().getWindow()).setAlwaysOnTop(true); + } + + private static void showAlwaysOnTop(Alert alert) { + showAlwaysOnTop(alert.getDialogPane()); + } + } diff --git a/src/main/java/com/kodedu/component/WindowModalAlert.java b/src/main/java/com/kodedu/component/WindowModalAlert.java index b70c4f60a..71db14512 100644 --- a/src/main/java/com/kodedu/component/WindowModalAlert.java +++ b/src/main/java/com/kodedu/component/WindowModalAlert.java @@ -2,17 +2,30 @@ import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; +import javafx.scene.control.DialogPane; import javafx.stage.Modality; +import javafx.stage.Stage; public class WindowModalAlert extends Alert { public WindowModalAlert(AlertType alertType) { super(alertType); super.initModality(Modality.WINDOW_MODAL); + showAlwaysOnTop(this); } public WindowModalAlert(AlertType alertType, String contentText, ButtonType... buttons) { super(alertType, contentText, buttons); super.initModality(Modality.WINDOW_MODAL); + showAlwaysOnTop(this); + } + + + private static void showAlwaysOnTop(DialogPane dialogPane) { + ((Stage) dialogPane.getScene().getWindow()).setAlwaysOnTop(true); + } + + private static void showAlwaysOnTop(Alert alert) { + showAlwaysOnTop(alert.getDialogPane()); } }