0

I need to give the user of a UI the option to switch between two border panes on clicking a button (or toggle switch or whatever).

The panes have the same job, size and position - it's just a different configuration so I don't want both of them there at the same time. When designing the UI in SceneBuilder I cannot place them at them same spot and set one visible and one invisible - because SceneBuilder obviously doesn't know that I want to stack them on top of each other.

Is there a way I can include both of them in the UI but only show one at a time?

I'd appreciate any ideas :)!

  • 1
    "_because SceneBuilder obviously doesn't know that I want to stack them on top of each other_" – What do you mean by that? If you use a `StackPane` the two will be stacked and you can simply toggle the visibility of each as needed (the latter part will need to be done in code, probably in the FXML controller). – Slaw Apr 29 '20 at 07:20
  • similar question here : https://stackoverflow.com/questions/8309802/how-can-i-implement-the-functionality-of-awt-cardlayout-in-my-javafx-2-0-applica – pdem Apr 29 '20 at 07:28
  • Does this help? [Switch between panes in JavaFX](https://stackoverflow.com/questions/16176701/switch-between-panes-in-javafx) – Abra Apr 29 '20 at 07:49

1 Answers1

0

What you are looking for is the CardLayout. See oracle's documentation on that: https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

Instead of adding your Components directly to the Component with the BorderLayout, instead add a JPanel which is using the CardLayout. Add the two Components to this JPanel.

Unfortunately I have no way to test this with the SceneBuilder right now, but you'll figgure out, how that works ;)

  • 1
    The question is about JavaFX, not Swing. They could probably embed Swing to make use of `CardLayout` but why do that when there's probably a pure JavaFX solution...? – Slaw Apr 29 '20 at 07:13
  • https://stackoverflow.com/questions/29271239/how-to-embed-jpanel-into-javafx-pane This would be the solution for including Swing in JavaFX – Bonebumble Apr 29 '20 at 07:31