Create wizard in JavaFX

后端 未结 4 2110
囚心锁ツ
囚心锁ツ 2020-12-17 05:56

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

4条回答
  •  情歌与酒
    2020-12-17 06:32

    Here's my solution, using ControlsFX Wizard classes, and FXML, with a non-modal wizard.

    WizardView.fxml:

    
    
    
    
    
        
            
                

    NB: Would be better to use a Wizard instead of an Anchor, but this would require LinearFlow being a public type, which is not the case by now (it's an inner class of Wizard in Java 1.8.0_144).

    WizardController.java:

    public class WizardController {
    
        @FXML
        private WizardPane step1Pane;
        @FXML
        private WizardPane step2Pane;
    
        ...
    
        void show() {
    
            Wizard wizard = new Wizard();
            wizard.setFlow(new Wizard.LinearFlow(
                    step1Pane,
                    step2Pane,
                    ...
            ));
            wizard.resultProperty().addListener((observable, oldValue, newValue) -> {
                wizardStage.close();
            });
    
            // show wizard and wait for response
            Stage wizardStage = new Stage();
            wizardStage.setTitle("... wizard");
            wizardStage.setScene(wizard.getScene());
    
            wizardStage.show();
        }
    }
    

    Application class:

    public class WizardApp extends Application {
    
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void init() throws Exception {
            super.init();
            ...
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(getClass().getResource("WizardView.fxml"));
            wizardController = loader.getController();
        }
    
        @FXML
        private void showWizard(ActionEvent actionEvent) {
            wizardController.show();
        }
    

    }

提交回复
热议问题