JavaFX 1.3: Managed Gets Promoted

Sometimes a node just doesn’t want its parent messing with its size or position.  In 1.2 you could use LayoutInfo to mark a node as ‘unmanaged’ to tell its parent Container not to factor it into layout and this concept was limited to Container parents.   With 1.3’s universal auto-sizing, suddenly all parents (Group, Container, CustomNode) care about managing their children, so we’ve moved the variable from LayoutInfoBase up to Node:

Button {
    managed: false // better than "layoutInfo: LayoutInfo { managed: false }"
    layoutX: 10 layoutY: 10 // parent will not layout, so must position myself
    width: 80  height: 45 // parent will not autosize, so must size myself
}

So if a node is unmanaged, its parent will not lay it out.   If inside a Group, this simply means the node will not be auto-sized.  If inside a Container, it means the node will not be factored into the container’s preferred size calculations and it will not set the node’s position (layoutX/Y) or size (width/height).  So…

  • Rule: If you unmanage a node then you are solely responsible for its position and size (if its Resizable);  and don’t go there unless you know what you’re doing.

Layout Roots

Another 1.3 affect of unmanaging a Parent node (Container, Group, CustomNode, or Control) is that it automatically becomes a layout root.  This means that layout requests beneath it do not propagate above it and instead cause the layout root itself to be added to the scene’s dirty layout list, where it’s branch will be layed out on the next pulse.    Before this change it was impossible to layout discrete branches of the scenegraph without laying out everything above it, which was a huge inefficiency.     This change gave a nice boost to the performance of our controls where there are many cases that size changes within the skins do not affect the overall layout bounds of the control and thus shouldn’t trigger relayout.

Here’s a practical example to illustrate how you might utilize a layout root.  Say you want to show a little ‘info’ graphic about a particular node.  You want this graphic to share the coordinate space of the node so its position always remains relative to it, but you don’t want it factored into the node’s layout in any way — sort of like a popup layer.   By making it an unmanaged child of the node, it won’t affect the node’s layout, but also size/layout changes within the info graphic will not trigger any re-layouts of the node itself.

blue and purple branches layed out independently

The only catch is to remember the Rule above, which is that if the layout root happens to be a Resizable (Container or Control), then you must take responsibility to manage its size since its parent node will be ignoring it.    If you don’t set its size then it’s like to have a size of 0 x 0 and won’t be visible.   On the other hand, if the layout root happens to be a Group, then auto-sizing will ensure that it and its contents get resized automagically during layout.

This entry was posted in Uncategorized. Bookmark the permalink.

6 Responses to JavaFX 1.3: Managed Gets Promoted

  1. Aleix says:

    Thaaaanksss Amy, your posts are really helpful !!! 🙂
    Go on with the good work !!!

  2. Pingback: JavaFX links of the week, May 17 // JavaFX News, Demos and Insight // FX Experience

  3. Pingback: Java desktop links of the week, May 17 | Jonathan Giles

  4. Pingback: JavaFX 1.3 Layout // JavaFX News, Demos and Insight // FX Experience

  5. ihsan says:

    Amy, you should know that we are waiting for new posts about javafx 2.0 layout management.

Leave a comment