javajavafxjfoenix

How to use .show() for JFXSnackbar in java fx


How to use .show() method on JFXSnackbar objects in javafx? when I use .show() method in my code the compiler shows me the message ".show() method is private in this library". I used jfoenix-8.0.8 version of jfoenix. Can anyone help out on this?


Solution

  • In the newest version of JFoenix (jfoenix-8.0.8), the show() method is purposefully encapsulated or hidden in the JFXSnackbar class. In other words, JFXSnackbar handles show() internally. See the public void enqueue(SnackBarEvent snackbarEvent) method. See screenshot of it here.

    To use a JFXSnackbar in a program you need to create a new JFXSnackbar object like so:

    JFXSnackbar snackbar = new JFXSnackbar(rootPane); 
    

    The rootPane is the pane that the snackbar will display on.

    Next, you need to create a JFXSnackbar.SnackbarEvent which will describe the behavior of the snackbar, like this:

    final JFXSnackbar.SnackbarEvent snackbarEvent = new JFXSnackbar.SnackbarEvent(new Label("Some string to display"), Duration.seconds(3.33), null);
    

    I used a null value for the Psuedoclass parameter. Still works fine.

    Finally, add the JFXSnackbar.SnackbarEvent to the JFXSnackbar object using enque method:

    snackbar.enqueue(snackbarEvent);