Extending a Region to create a JUNG Layout
richard.bair at oracle.com
Fri May 30 18:07:16 UTC 2014
> It would be nice if Oracle or somebody else produced some documentation on this. You could create a feature request in Jira (https://javafx-jira.kenai.com) for such documentation or email the documentation team (javasedocs_us at oracle.com), or write a blog or a openjfx wiki article (https://wiki.openjdk.java.net/display/OpenJFX/Main) if you work out some good techniques.
Thanks John, that is good advice.
> Can someone point me to a detailed explanation of how to extend Region to create my own layout?
> In particular, how can I get a region to relayout it's children when it's being resized?
Some quick pointers. First, layout is done asynchronously to the changes that cause the layout to have to occur. This is done so that we limit the number of times we layout a container. For example, if a container’s width changes, we mark that container (and on up the hierarchy) as needing a new layout, but we don’t perform the layout yet. If you were to then change the height for a container, we see that it has already been marked dirty and don’t have to go any further. Without this, we ended up with “layout storms”.
Layouts happen once “per pulse”. A “pulse” happens once per rendering. So we get notification that we need to prepare the scene graph in order to render the next frame. So we do CSS, layout, etc and then synchronize those changes down to the graphics layer to draw. You don’t have to worry about the pulse. Just know that when the width / height / etc of a layout container changes, we mark it as dirty, and then perform layout *sometime before the next render happens*.
In order to manually tell a region that it has a dirty layout, call requestLayout() on the region.
> When does a the region's parent call layoutChildren()?
During the pulse. You can force a layout (which maybe is what you’re bumping up against), but normally if you can, you want to let the “once per pulse” mechanism cause layout to occur for you.
During the layout pass, the layoutChildren() method on the region will be called. Inside this method you are responsible for taking into account any insets on the region (by calling getInsets()).
> If the height and width of the region are set to Double.MAX_VALUE indicating the area can grow infinitely, how does the region know what size to set itself to?
I assume you mean, when the prefWidth and prefHeight? The parent of the region will ask the region for its min/pref/max width and height, and will then decide what size to give your region. So in other words, the region doesn’t figure out its own width/height, it is told its width and height, *prior* to be being asked to layout its children.
More information about the openjfx-dev