Show Alert JavaFX - java

When the alert is opened, this minimized the main window, displays the alert, when I close the alert, returns to the main window.
It is possible that the alert is displayed above the main window ??
Thanks.
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setTitle("Information Dialog");
alert.setHeaderText("Look, an Information Dialog");
alert.show();
Thanks.

Please set the owner of the alert box like below
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(primaryStage);
Cheers

Related

Javafx : Dialog pane reference

I have a controller, which contains buttons, if I press one button an Alert shows, with Yes and No options, and I want to write a test for this controller class testing the result of this Alert, for example if I press the Yes button what happens. I could get the Window/Stage, and the Scene, but how can I get the Alert from the controller which popped up. Is that the primaryStage or I don't really understand how can I get it. I had a look at the hierarchy of the Alert and it doesn't have any relation with the Stage or Scene or just I didn't observed it. Is there a possibility to get a reference of the Alert or of its buttons?
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Confirmation Dialog");
alert.setHeaderText("Look, a Confirmation Dialog");
alert.setContentText("Are you ok with this?");
Optional<ButtonType> result = alert.showAndWait();
if (result.get() == ButtonType.OK){
// ... user chose OK
} else {
// ... user chose CANCEL or closed the dialog
}
This code above does what you need.
Look here for more
And you can always consult java docs.

AlertDialog shows SystemUiVisibility

I am making an android game and i set my SystemUiVisibility with the setSystemUiVisibility to not show the top bar and other system ui's, but now when u die in game i want to show an AlertDialog with the score you have. When i show the AlertDialog it brings the SystemUiVisibility back and i dont want to have that happen. Does someone know how to fix that. Here is the code i am using right now for the AlertDialog:
dlgAlert.setMessage("You lost, you hit the right color " + Points + " times");
dlgAlert.setTitle("You died");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.create().show();
Make the Dialog non-focusable when we create it (so we don't trigger a user-interaction) and then make it focusable after it's displayed.
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
//Show the dialog!
dialog.show();
//Set the dialog to immersive
dialog.getWindow().getDecorView().setSystemUiVisibility(
context.getWindow().getDecorView().getSystemUiVisibility());
//Clear the not focusable flag from the window
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);

JFace MessageDialog is not showing the body(dialog area) by default

I am creating a JFace MessageDialog
MessageDialog md = new MessageDialog(null, "Title", null,
"Body message", SWT.YES | SWT.NO, new String[] { Messages.yes, Messages.no }, 0);
On one Windows 7 machine when this dialog is opened, it doesn't show its body/dialog area until user presses the Enter key and only title bar is displayed without body. Moreover its position is left bottom corner of the screen. While on pressing the Enter key it opens the dialog in a proper manner and user can see the "Body message" and Yes No buttons on it.
Is it related to some windows or java setting on that machine?

How to check all items in multichoice alert box by providing a SELECTALL CHECKBOX programmatically

Hi I have an alert dialog with multichoice check box & i want to set one select all checkbox so that by clicking this SELECTALL CHECKBOX all items(i.e checkbox ) in the alert dialog list will automatically select programmatically.
Kindly help me.Thanks in advance.
You can read my answer here or example here or continue reading...
You need to setMultiChoiceItems(R.array.items, null, null) on AlertDialog.Builder and after that, get the ListView from an onCreated and shown dialog and setOnItemClickListener with little logic and you are done. Check my example here

Making a JDialog always on top of application

I'm making a program that requires this jdialog box to always be focused and on top, ie: make the ding sound when i click on the parent window. here's what i have so far:
JDialog dialog = new JDialog();
// dialog.setAlwaysOnTop(true);
dialog.setSize(400, 220);
dialog.setLocationRelativeTo(relativeTo); //relativeTo is the name of parent frame
dialog.setVisible(true);
// dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
// dialog.setModal(true);
(the commented things are those i have tried unsuccessfully...)
how would i make this dialog box ontop of the parent window? any help would be great! thanks
You need to set the dialog's owner and make the dialog modal:
JDialog dialog = new JDialog(parentFrame, true); // owner, modal

Categories

Resources