Adjust JFXDialog to its StackPane

556 Views Asked by At

So I have this line of code which shows a Dialog:

public void showInfoDialog(String header,String message) {
    JFXDialogLayout content = new JFXDialogLayout();
    content.setHeading(new Text(header));
    content.setBody(new Text(message));
    JFXDialog dialog = new JFXDialog(mySP,content, JFXDialog.DialogTransition.CENTER);
    dialog.setMinHeight(mySP.getPrefHeight());
    dialog.setMinWidth(mySP.getPrefWidth());
    JFXButton button = new JFXButton("OK");
    button.setOnAction((ActionEvent event) -> {
        dialog.close();
    });
    content.setActions(button);
    dialog.show();
}

And that is leading to this output: dialog

How can I adjust the height and width of the dialog so I can't see the grey background of my stackpane

1

There are 1 best solutions below

0
On

You can just set a maximum size for the Dialog, or simply adjust the size of the stackPane you set for reference.

Try to add this to your code:

dialog.setMaxSize(100, 100); //For example

It'll just adjust the size of your stackPane and make it as the same size of your dialog.