How to bind stage resizing with resizing of components?

前端 未结 3 1626
春和景丽
春和景丽 2020-12-08 11:40

I have a JavaFX 2.0 application with FXML. I want the components (TextFields, ComboBoxes, layouts, and so on) to be resized when a window with an application is resized. So

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 12:14

    Suggestions:

    1. If you have only one main stage then store it in a static field/variable while the app start and access it in all controller classes.
    2. You can put all controls/components into a layout/pane that manages its children layout automatically. For different layouts check the api doc. After that, bind the stage scene's width and height properties to this layout's properties accordingly. More on binding look at Using JavaFX Properties and Binding.
      Example of unidirectional binding

提交回复
热议问题