如何从start方法中访问stage对象

时间:2015-09-19 06:25:46

标签: javafx fxml stage

public class grandParent extends Application {
    public Stage primaryStageClone = null;
    @Override
    public void start(Stage primaryStage) throws Exception{
        primaryStageClone = primaryStage;
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("searchBar.fxml"));
        final Parent root = (Parent) fxmlLoader.load();
        primaryStageClone.initStyle(StageStyle.TRANSPARENT);
        Scene scene = new Scene(root);
        scene.setFill(Color.TRANSPARENT);
        primaryStageClone.setScene(scene);
        primaryStageClone.setHeight(600);
        primaryStageClone.show();
//primaryStageClone working here....
    }

    public void keyPressedHandler() {
        System.out.println("Now in keyPressedHandler()");
        try{
            primaryStageClone.setHeight(600);//Unable to access here ....It gives exceptions...
        }catch(Exception e){
            primaryStageClone.setHeight(600);
        }

    }

    public static void main(String[] args) {
    // write your code here

        launch(args);
    }
}

我有问题从start()中访问对象..我想在keyPressedHandler()中访问它...我在javafx中的新功能帮助我弄清楚我的错误...谢谢

0 个答案:

没有答案