VOOZH about

URL: https://www.javacodegeeks.com/2014/08/javafx-tip-14-stackpane-children-hidden-but-not-gone.html

⇱ JavaFX Tip 14: StackPane Children – Hidden But Not Gone


Another short tip: Swing provides a layout manager called CardLayout, which manages a set of components (cards) inside a container but always only shows one of them. The method CardLayout.show(Container, String) allows to switch between the components / the cards.

The same behaviour can be accomplished in JavaFX by using the StackPane, adding several children (each using the entire width and height of the pane) and calling the Node.toFront() method to switch between the children. However, there is one big difference: the StackPane will always layout all of its children, independent of wether they are currently showing or not. This might result in bad performance of your application and can be noticed when resizing the window that contains the pane.

My advice: manage your “cards” by adding them to or removing them from the scene graph. These operations are fast and flicker-free (this is JavaFX in Java 8, not Swing before Java 6).

Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

Tags
JavaFX
👁 Photo of Dirk Lemmermann
Dirk Lemmermann
August 27th, 2014Last Updated: August 26th, 2014
2 254 1 minute read
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

2 Comments
Oldest
Newest Most Voted
Sebastian
8 years ago

Well, imagine that one of your “card” is a form. If you switch between the “cards” during completing this form, you loose your data if remove the card during switching.

0
Reply
8 years ago
Reply to  Sebastian

Only remove the cards from the SceneGraph, do not delete / dispose them.

0
Reply
Back to top button
Close
wpDiscuz