通过控制器完成初始化后的JavaFX FadeTransition

通过控制器完成初始化后的JavaFX FadeTransition,javafx,fade,transitions,Javafx,Fade,Transitions,我有以下申请: public class FOO extends Application { private Scene scene; @Override public void start(Stage stage) throws Exception { stage.initStyle(StageStyle.UNDECORATED); stage.setScene(scene); stage.show(); }

我有以下申请:

public class FOO extends Application {

    private Scene scene;

    @Override
    public void start(Stage stage) throws Exception {
        stage.initStyle(StageStyle.UNDECORATED);
        stage.setScene(scene);
        stage.show();
    }

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

    @Override
    public void init() throws Exception {

        URL resource = FXMLTabPaneController.class.getResource("FXMLTabPane.fxml");
        System.out.println(resource);
        Parent root = FXMLLoader.load(resource);

        scene = new Scene(root);
    }

}
作为一个控制器:

public class FXMLTabPaneController implements Initializable {

@FXML
private TabPane tabPane;

@FXML
private AnchorPane anchorPane;

@Override
public void initialize(URL url, ResourceBundle rb) {
    FadeTransition fadein = new FadeTransition(Duration.seconds(5), tabPane);
    fadein.setFromValue(0);
    fadein.setToValue(1);
    fadein.play();

}

}
我想在应用程序启动后缓慢地显示选项卡窗格,但它是从已经看到的应用程序选项卡窗格开始的

试试这个:

public class FXMLTabPaneController {

    @FXML
    private TabPane tabPane;

    @FXML
    private AnchorPane anchorPane;

    @FXML
    private void initialize() {

    }

    public void show(WindowEvent event) {
        FadeTransition fadein = new FadeTransition(Duration.seconds(5), tabPane);
        fadein.setFromValue(0);
        fadein.setToValue(1);
        fadein.play();
    }
}
和富班

public class FOO extends Application {

    private Scene scene;
    private FXMLTabPaneController controller;

    @Override
    public void init() throws Exception {
        super.init();
        URL resource = FXMLTabPaneController.class.getResource("FXMLTabPane.fxml");
        System.out.println(resource);

        FXMLLoader loader = new FXMLLoader();
        loader.setLocation(resource);

        Parent root = loader.load();
        controller = loader.getController();

        scene = new Scene(root);
    }

    @Override
    public void start(Stage stage) throws Exception {
        stage.setOnShown(controller::show);

        stage.initStyle(StageStyle.UNDECORATED);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}