javafx如何在FXML控制器中使用controlfx对话框

时间:2014-07-16 17:01:52

标签: java javafx javafx-8 javafx-2 controlsfx

如何在fxml控制器中打开一个对话框,因为它需要stage

 Dialogs.create()
    .owner(---what should i write here---)
    .title("Information Dialog")
    .masthead("Look, an Information Dialog")
    .message("I have a great message for you!")
    .showInformation();

我添加了以下jar

controlsfx-8.0.6_20.jar
controlsfx-samples-8.0.6_20.jar
fxsampler-1.0.6_20.jar

请帮帮我。

1 个答案:

答案 0 :(得分:1)

所有者是对话窗口将使用的阶段。:

import org.controlsfx.dialog.Dialogs;
import javafx.application.Application;
import javafx.stage.Stage;

public class Diag extends Application{

    @Override
    public void start(Stage primaryStage) throws Exception {
        Dialogs.create()
        .owner(primaryStage)
        .title("Information Dialog")
        .masthead("Look, an Information Dialog")
        .message("I have a great message for you!")
        .showInformation();
    }
    public static void main(String[] args) {
        launch(args);
    }

}

并且您可能想将其称为对话框,您也可以将其称为:

        Dialogs.create()
        .owner(new Stage())
        .title("Information Dialog")
        .masthead("Look, an Information Dialog")
        .message("I have a great message for you!")
        .showInformation();