Perhaps, `primaryStage.scene.height`?
# tornadofx
v
Perhaps,
primaryStage.scene.height
?
s
Hmm, it says that my primaryStage.scene is null, which is very confusing. According to the JavaFX doc the
start(stage)
method is called immediately after the App is initialized, which is called before the View gets instantiated I would assume, since the View is inside the stage.. unless I'm understanding it incorrectly.
v
Well, perhaps, you're trying to get it's value somewhere in declaration, before the object is created
Copy code
public void start(Stage stage) {
       Group root = new Group();
       Scene scene = new Scene(root, 500, 500, Color.BLACK);
       stage.setTitle("JavaFX Scene Graph Demo");
       stage.setScene(scene);
       stage.show();
   }
In the example above you cannot use
stage.height
for
root
If you need to set view's height on init,
init { ...; runlater { this.prefHeight = primaryStage.height }; ... }
c
@Shan the UI needs to render before you can get geometry (height, etc)
the correct place to put geometry-based initialization is in the onDock() method which in JavaFX terms is the OnShown event
@ValV that runLater() may not be reliable as the FX thread may be active but the OS window may not be rendered. You might find this doesn't work on other platforms or if the init timing changes
v
Hmm, thanks for warning (in my case
runLater
worked fine)
And
primaryStage.scene.height
instead of just
primaryStage.height
c
yeah. you've been lucky. but there's no guarantee that that runLater() will be executed after the OnShown
move then when you can or you'll one day add an extra step as part of an enhancement and get an error out of the blue
s
@carlw thanks for the response! so the correct place to get the stage height would be in the overrided onDock() method in my initial View that I pass to my App when the application starts, yes?
c
yes. "dock" is referring to a lifecycle event involving dockable windows but it's actually OnShown if you want to read about it in the javafx javadocs
look for "Stage"
s
Unfortunately it still returns as NaN when I put it in the overrided onDock method in my home view. I will go read more into the JavaFX lifecycle to see what's going on I suppose
c
can you post a little code?
s
Sure, one sec
c
we take javafx code here