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

时间:2014-10-03 09:27:40

标签: 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;
}

}

1 个答案:

答案 0 :(得分:1)

问题是我忘了添加

openjfx-dialogs.jar