Is there any example how to create wizard in JavaFX?
For example to setup a program or for configuration. Can this be done with simple code or I need to create cust
Using the http://fxexperience.com/controlsfx/ library the following code works for me. It uses fxml files for each wizard page. The helper function runWizard then loads the resources and creates pages from it. Of course you can modifiy the content as outlined in ControlsFX 8.20.7 Wizard examples - getting Wizards to work
Usage of runWizard
String[] pageNames = { "page1","page2","page3" };
Platform.runLater(() ->{
try {
runWizard(I18n.get(I18n.WELCOME),"/com/bitplan/demo/",pageNames);
} catch (Exception e) {
ErrorHandler.handle(e)
}
});
ControlsFX Maven dependency
org.controlsfx
controlsfx
8.40.12
runWizard helper function
/**
* run the wizard with the given title
* @param title - of the wizard
* @param resourcePath - where to load the fxml files from
* @param pageNames - without .fxml extenion
* @throws Exception - e.g. IOException
*/
public void runWizard(String title,String resourcePath,String ...pageNames) throws Exception {
Wizard wizard = new Wizard();
wizard.setTitle(title);
WizardPane[] pages = new WizardPane[pageNames.length];
int i = 0;
for (String pageName : pageNames) {
Parent root = FXMLLoader.load(getClass()
.getResource(resourcePath + pageName + ".fxml"));
WizardPane page = new WizardPane();
page.setHeaderText(I18n.get(pageName));
page.setContent(root);
pages[i++] = page;
}
wizard.setFlow(new LinearFlow(pages));
wizard.showAndWait().ifPresent(result -> {
if (result == ButtonType.FINISH) {
System.out
.println("Wizard finished, settings: " + wizard.getSettings());
}
});
}