return values from javafx dialog


I created a form with javafx that opens a login dialog, after the user enters the login information correctly the dialog closed and the main form loaded some data, what I need is that when the login dialog is closed it would return the user id (which make the login) to the main form, the code of the above case is like that:

The main form

 Stage loginDialog = new LoginDialog(stage);

the login dialog form

/* do the login */
/* need to return thew user id to the main form*/

Any help please

5/29/2013 9:36:09 AM

Accepted Answer

The first thing I would suggest is to create your own simple dialog box. The controlsFX stuff is cool, but my experience has been that some of the controls are overly complex and others have bugs. Here is an abridged example.

public class DialogBox {
    private static String[] login;

    public static String[] display(String title, String message) {
        Stage window = new Stage();
        Label label = new Label(message);

        // Set up the JavaFX button controls and listeners and the text fields
        // for the login info. The button listeners set the login values

        window.setScene(new Scene(root, 300, 175);
        return login;

As you can see, there is a single static method called display() that returns a String array that contains the user login information. Simply do a static call to this method as follows.

String[] login = DialogBox.display("Login Dialog", "Enter User Name and Password");
7/21/2017 9:00:19 PM

Your answer is ControlsFX library. I have posted here.

This library allows you to get return value from a dialog box. The best of all, you can create your own customized dialog box.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow