Reputation: 223
I have AnchorPane created with SceneBuilder and corresponding Scene and Stage. AnchorPane contains VBox. All sizes of AnchorPane are USE_COMPUTED_SIZE. Heght of VBox is changed programmicaly, but sizes of Scene and Stage do not change.
How can I make them being autoadjusted to content size?
Upvotes: 5
Views: 9755
Reputation: 181
The start() method of your Application class is passed a Stage object (called stage by the Wizard). If you declare a member variable of type Stage in that class (mStage), then the first thing you do in start() is save it:
mStage = stage ;
You can now do this anytime you need to (in your Application class of course):
mStage.sizeToScene() ;
If you need to do it from your controller class, you can give your controller a reference to your Application (or probably better, have your Application class implement an interface for the controller). Ah, you say, but my Application class doesn't have a reference to the controller, and visa-versa). Well, I've never liked the code that is generated by the wizard, because inflates the controller from the XML file without giving you a reference to it, which makes using the document-view-controller pattern hard. If you want to see how you can get a reference to the controller, see slide 8 (not page 8) of the following. If you further want to instantiate and then specify your own controller (I have a use case for which that is highly desirable) see slides 10 and 11:
Upvotes: 14