【发布时间】:2015-12-16 08:53:09
【问题描述】:
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 的新手,帮助我找出我的错误...谢谢
【问题讨论】:
-
您是否使用您的
Application子类作为您的控制器?如果是这样,请不要。 -
不,我有不同的控制器...
-
你能说明你是怎么打电话给
keyPressedHandler()的吗?并发布堆栈跟踪。