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?
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:
https://docs.google.com/viewer?a=v&pid=sites&srcid=ZGVmYXVsdGRvbWFpbnxwc2NoaW1wZjk5fGd4OjVlODJiOTg2OTVlYzky
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With