java - ControlsFX 8.20.7 向导示例 - 让向导工作

标签 java javafx controlsfx

我正在尝试使用新的 ControlsFX 8.20.7 版本开发向导。我看过以下示例:BitBucket ControlsFX ,尤其是方法

showLinearWizard() 

我根本不明白如何使用这个 API,任何人都可以帮助我开始或链接到一些示例吗?

这是我现在的代码,充满了错误:

public class WizardTest extends Application {

private final ComboBox<StageStyle> styleCombobox = new ComboBox<>();
private final ComboBox<Modality> modalityCombobox = new ComboBox<>();
private final CheckBox cbUseBlocking = new CheckBox();
private final CheckBox cbCloseDialogAutomatically = new CheckBox();
private final CheckBox cbShowMasthead = new CheckBox();
private final CheckBox cbSetOwner = new CheckBox();
private final CheckBox cbCustomGraphic = new CheckBox();

private Stage stage;

@Override
public void start(Stage primaryStage) {
    Button btn = new Button();
    btn.setText("Say 'Hello World'");
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            showLinearWizard();
        }
    });

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

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

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();

}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);

}

private void showLinearWizard() {
    // define pages to show

    Wizard wizard = new Wizard();
    wizard.setTitle("Linear Wizard");

    // --- page 1
    int row = 0;

    GridPane page1Grid = new GridPane();
    page1Grid.setVgap(10);
    page1Grid.setHgap(10);

    page1Grid.add(new Label("First Name:"), 0, row);
    TextField txFirstName = createTextField("firstName");
    wizard.getValidationSupport().registerValidator(txFirstName, Validator.createEmptyValidator("First Name is mandatory"));  
    page1Grid.add(txFirstName, 1, row++);

    page1Grid.add(new Label("Last Name:"), 0, row);
    TextField txLastName = createTextField("lastName");
   wizard.getValidationSupport().registerValidator(txLastName, Validator.createEmptyValidator("Last Name is mandatory"));
    page1Grid.add(txLastName, 1, row);

    WizardPane page1 = new WizardPane();
    page1.setHeaderText("Please Enter Your Details");
    page1.setContent(page1Grid);

    // --- page 2
    final WizardPane page2 = new WizardPane() {
        @Override
        public void onEnteringPage(Wizard wizard) {
            String firstName = (String) wizard.getSettings().get("firstName");
            String lastName = (String) wizard.getSettings().get("lastName");

            setContentText("Welcome, " + firstName + " " + lastName + "! Let's add some newlines!\n\n\n\n\n\n\nHello World!");
        }
    };
    page2.setHeaderText("Thanks For Your Details!");

    // --- page 3
    WizardPane page3 = new WizardPane();
    page3.setHeaderText("Goodbye!");
    page3.setContentText("Page 3, with extra 'help' button!");

    ButtonType helpDialogButton = new ButtonType("Help", ButtonData.HELP_2);
    page3.getButtonTypes().add(helpDialogButton);
    Button helpButton = (Button) page3.lookupButton(helpDialogButton);
    helpButton.addEventFilter(ActionEvent.ACTION, actionEvent -> {
        actionEvent.consume(); // stop hello.dialog from closing
        System.out.println("Help clicked!");
    });

    // create wizard
    wizard.setFlow(new LinearFlow(page1, page2, page3));

    System.out.println("page1: " + page1);
    System.out.println("page2: " + page2);
    System.out.println("page3: " + page3);

    // show wizard and wait for response
    wizard.showAndWait().ifPresent(result -> {
        if (result == ButtonType.FINISH) {
            System.out.println("Wizard finished, settings: " + wizard.getSettings());
        }
    });
}

private TextField createTextField(String id) {
    TextField textField = new TextField();
    textField.setId(id);
    GridPane.setHgrow(textField, Priority.ALWAYS);
    return textField;
}

}

最佳答案

问题是我忘了添加

openjfx-dialogs.jar

关于java - ControlsFX 8.20.7 向导示例 - 让向导工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176498/

相关文章:

java - 在 Equinox osgi 中使用 commons.fileupload 时出现 ClassNotFoundException :org. apache.commons.io.output.DeferredFileOutputStream 错误

javafx如何在FXML Controller 中controlfx对话框

用于 RangeSlider 的 JavaFX ControlsFX CSS

java - ControlsFX - 线程异常“ControlsFX 错误 : ControlsFX 8. 40.10 至少需要 Java 版本 8 更新 40

java - 获取 String.replaceAll() 删除的内容

c# - 什么时候应该封装泛型类型?

java - 从其他线程访问 while 循环 bool 是线程安全的吗?

Java - 将元素添加到列表中时出错

java - 如何限制javafx垂直flowpane中的列数

java - 故意在 JavaFX windows 应用程序上重现应用程序崩溃 "Application has Stopped Working"