2014-10-03 51 views
2

我正在嘗試使用新的ControlsFX 8.20.7版本開發嚮導。我已經採取了看看下面的例子:BitBucket ControlsFX,尤其是方法ControlsFX 8.20.7嚮導示例 - 讓奇才工作

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; 
} 

} 
+0

這個來源爲我工作。 究竟是什麼問題? 我正在使用ControlsFX 8.20.7。 – Kalaschni 2014-10-06 08:29:33

回答

1

的問題是,我忘了加上

openjfx-dialogs.jar 
+0

你不需要任何第三方jar。 只有controlsFX 8.20.7罐子 – Kalaschni 2014-10-08 09:01:06

+0

這是錯誤的。你需要openjfx-dialogs.jar。這是發行說明。 – miniHessel 2014-10-08 09:36:21

+0

啊,對不起。如果我使用Maven並將controlsFX作爲依賴項添加,openjfx-dialogs.jar會自動添加(繼承)。 – Kalaschni 2014-10-08 09:56:53