0

I'm trying to show a simple dialog on the screen with JFoenix, however, every time I try to show, I get an error,"The JFXDialog container is not set" I know this means that stackPane was not shown, so I would like to know how to initialize StackPane and then show the dialog

The function:

@FXML
public StackPane stack;

public void show() {
    JFXDialog dialog = new JFXDialog();
    dialog.setContent(new Label("Content"));
    dialog.show(stack);
}

the stackpane was created using the JavaFX Scene builder, it is a child of the rootPane, which is an anchor pane

  • Can you post the code you are using that generates this error? – Nick Jun 19 '18 at 17:56
  • Ready, edited post – Death Awaits Jun 19 '18 at 19:01
  • Can you post the full error (stack trace)? Also, what version of Java and JFoenix are you using? I just tried something very similar to your code with JDK 10.0.1 and JFoenix 9.0.4 and no exception was thrown. I even tried calling `dialog.show(null)` in case your `stack` is `null` but that resulted in a `NullPointerException` and not a "_The JFXDialog container is not set_" error. – Slaw Jun 20 '18 at 11:06
  • I'm using JFoenix 8.0.1, with JDK 8. I only get the "The JFXDialog container is not set" error, nothing more. But I did a search on the internet, and they said that I need to initialize StackPane before calling the Dialogo, for example, using a StackPane as root. However, I already built the entire layout with an AnchorPane as a base – Death Awaits Jun 20 '18 at 14:35

1 Answers1

0

Even though some time has happened since you posted the question, other people may be going through the same issue these days.

JFXDialog requires a) a JFXDialogLayout and b) a container, which in your case is a StackPane. So, to make it work, you must indicate to your JFXDialog what's the container. This can be done by using the constructor JFXDialog dialog = new JFXDialog(stack, layout, JFXDialog.DialogTransition.RIGHT);. That is:

@FXML
public StackPane stack;

public void show() {
    JFXDialogLayout layout = new JFXDialogLayout();
    layout.setHeading(new Label("Header"));
    layout.setBody(new Label("Lorem ipsum"));

    JFXDialog dialog = new JFXDialog(stack, layout, 
                             FXDialog.DialogTransition.RIGHT);
    JFXDialog.DialogTransition.RIGHT);
    dialog.show();
}

This should do the job.