Switch between panes in JavaFX

后端 未结 3 878
醉话见心
醉话见心 2020-12-02 17:22

I\'m trying to make a Java program in JavaFX using FXML. However i\'m having trouble with the layout management. I want to switch between Panes, just as i\'m used to with Ca

3条回答
  •  囚心锁ツ
    2020-12-02 18:15

    Non-animated transitions

    If you don't need animated transitions between your panes, then you can:

    1. Replace the whole scene by creating a new scene and set that scene on your Stage OR
    2. Replace just a specific pane in a parent layout, by removing the old pane from it's parent and adding your new pane (by manipulating the parent's children list) OR
    3. Place all your Panes in a StackPane and move the pane you want to display to the top of the stack's child list.

    Animated transitions

    If you would like animated transtions between your panes, then see Angela Caicedo's two part series on managing multiple screens in JavaFX:

    • Part I
    • Part II

    Angela's solution is to use a StackPane with a separate custom ScreenController class for managing Transitions or animations between panes in the stack.


    Frameworks

    Frameworks like JFXFlow and WebFX can also provide a browser style interface for your app, allowing users to switch back and forth between screens using back and forward buttons and a history list.

    Update 2017

    I think development on both referenced frameworks above is now defunct. Other frameworks which are under development are:

    • TornadoFX
    • JRebirth
    • afterburner.fx

    And numerous others (I won't provide a comprehensive list here).


    Related

    • Loading new fxml in the same scene

提交回复
热议问题