javajavafx-8jfxtras

JFXtras MonologFX - How to detect which button was pressed


I was testing the MonologFX from JFXtras (v8.0-r5), but I got stuck with it!

Can anyone tell me how to check what was the button in the dialog that was pressed by the user? I tried in many ways, but no luck at all.

package javafx_jfxtras_monologfx;

import javafx.application.Application;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane; 
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.event.EventHandler;
import javafx.event.ActionEvent;
import jfxtras.labs.dialogs.MonologFX;
import jfxtras.labs.dialogs.MonologFXButton;
import jfxtras.labs.dialogs.MonologFX.Type;

public class JavaFX_JFXtras_MonologFX extends Application
{
    @Override
    public void start(Stage stage)
    {
        MonologFX m = new MonologFX();
        m.setModal(true);
        m.setType(Type.QUESTION);
        m.setTitleText("JFXtras MonologFX");
        m.setMessage("Do you want to continue?");
        m.setPos(698, 450);

        MonologFXButton mb1 = new MonologFXButton();
        mb1.setType(MonologFXButton.Type.YES);
        mb1.setLabel("Continue");
        m.addButton(mb1);

        MonologFXButton mb2 = new MonologFXButton();
        mb2.setType(MonologFXButton.Type.NO);
        mb2.setLabel("Exit");
        m.addButton(mb2);

        Button btn = new Button();
        btn.setText("Click the Button");
        btn.setOnAction(new EventHandler<ActionEvent>()
        {
            @Override
            public void handle(ActionEvent event)
            {
                System.out.println("Hello :)");
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);

        Scene scene = new Scene(root, 300, 250);

        stage.setTitle("JavaFX - JFXtras MonologFX");
        stage.setScene(scene);
        stage.show();

        m.show();
    }
  
  
    public static void main(String[] args)
    {
        launch(args);
    }
}

Solution

  • But the controls in labs are experimental and Mark has not worked on this one for a long time. We don't take them out because someone may use them, but as of version 8u40 JavaFX has a dialog itself. https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Dialog.html|