Skin layoutChildren: when to get bounds of child nodes?

Richard Bair richard.bair at oracle.com
Fri Jul 25 16:56:31 UTC 2014


Hmmm. The first question I have is whether boundsInParent is really what you want to use, vs. layout bounds. But assuming it is what you want, why are the bounds zero? This is during the layout pass, which is the right place to be doing what you’re doing. The super layoutChildren call will size everything based on the contentX, contentY, contentWidth, contentHeight (http://hg.openjdk.java.net/openjfx/8u-dev/rt/file/4b8d06211312/modules/controls/src/main/java/javafx/scene/control/SkinBase.java). Is it possible that the parent itself is size 0? boundsInParent should always be invalidated automatically whenever the width/height/transforms/etc changes. If not that is definitely a bug (that you can write a simple test case for to prove).

But my first guess is maybe the parent is size 0 as well, due to something else (maybe the pref size of the control is 0 to start with or something…)

Richard

On Jul 24, 2014, at 3:34 AM, Werner Lehmann <lehmann at media-interactive.de> wrote:

> Hi,
> 
> inside a control skin I have the following code pattern:
> 
>  protected void layoutChildren(...)
>  {
>    super.layoutChildren(...);
> 
>    Node child1 = ...
>    Bounds bip = child1.getBoundsInParent();
> 
>    if (!animating) {
>      Node child2 = ...
>      child2.setTranslateX(bip.getMinX();
>      child2.setPrefWidth(bip.getWidth());
>    }
>  }
> 
> The skin scene graph looks roughly like this:
> 
> VBox
>  HBox { ..., child1, ...}
>  child2
>  ...
> 
> Everything is layouted just fine but I want to adjust child2.translateX and prefWidth based child1 bounds. This does not work initially because boundsInParent returns zero components leading to incorrect initial display of the control.
> 
> Seems as if boundsInParent is not yet updated. I guess I could use a binding for that but it would conflict with an animation I also have on translateX and prefWidth.
> 
> Maybe there is a better time to make those adjustments on child2?
> 
> Rgds
> Werner



More information about the openjfx-dev mailing list