Skip to content

Commit

Permalink
Show dialog allways in front
Browse files Browse the repository at this point in the history
  • Loading branch information
rahmanusta committed Aug 18, 2018
1 parent 79826e1 commit 4584157
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/kodedu/component/AlertDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
}

}
1 change: 1 addition & 0 deletions src/main/java/com/kodedu/component/AlertHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/kodedu/component/DialogBuilder.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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() {
Expand Down Expand Up @@ -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());
}

}
14 changes: 14 additions & 0 deletions src/main/java/com/kodedu/component/TextDialog.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
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.
*/
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) {
Expand All @@ -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());
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/kodedu/component/WindowModalAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}

0 comments on commit 4584157

Please sign in to comment.