JavaFX Node Bounds: I don’t get it

I’m happy to admit it when I don’t get something. The situation with boundsInLocal, layoutBounds, and boundsInParent in JavaFX is one of these situations. I have read a number of articles discussing this topic, and whilst I understand the differences between the three values technically, I don’t think I’ve seen an article that tells me why I need all three values, and when I should choose one over the other.

So, please, can someone out there write a blog post and/or add a comment to this post to explain to me, and to others, why I need to care about these three different values. If you do write a separate blog post, please leave a comment here so that anyone who stumbles upon this blog post in 6 months time can follow through to any other discussions elsewhere.

Most importantly, keep it simple. I know, that’s more difficult than being complex and detailed, but for the sake of JavaFX clarity the world over, please keep it simple. We want to know, simply, why and when do I care about the three different values?

Thanks in advance!

7 Responses to “JavaFX Node Bounds: I don’t get it”


  • Jon,

    I may not get it either, but what I think I get is:

    I think the three values depends on the situation because nodes go through so much from transformations to translation its hard to position things in relation to one another. I guess on a scene graph you need finer grain properties.

    Here are the sites I always go back to:
    Baechul Kim
    http://blogs.sun.com/baechul/entry/node_bounding_rectangles_coordinates

    Amy Fowler
    http://weblogs.java.net/blog/aim/archive/2009/01/layout_primer_f.html

    -Carl

    • @Carl Dea: Those links are good references, but like I said, they are too technical. Also, Amy’s post is for JavaFX 1.0, and things have changed a bit in relation to the three node bounds variables since then. It is no longer a reliable source for JavaFX 1.2 onwards.

      What I really want to know, as a developer using JavaFX, is should I have a bad feeling about not knowing when I should use each of these?

      The problem is that if no one gives me a good, simple explanation, that I’ll have to go into ‘hack’ mode when I start needing to do bounds calculations – I’ll simply keep hacking at code until I get the right value. It’s uninformed, slow, and clearly not ideal.

      I’m playing devils advocate a little – I don’t think it’s necessary to know this stuff in too much detail, but regardless, I would like to see if someone can simplify this for me and others. I’m certain the confusion is fairly widespread.

      – Jonathan

      • Jon,

        Agreed.. I too want a simpler and general user guidelines when to use them and why. Looking forward to Amy Fowler’s blog entry, and many others. You should still go back and ‘hack’ it helps the mind. ;-)

        Thanks,

        -Carl

  • The main problem with all the explanations is that they forget to explain what coordinate spaces they are talking about; “they are relative to the rectangle’s coordinate space”… What in the world is that???

    I understand that you have an x,y,w,h and that these values are changed due to effects, etc, but they first need to layout the foundation before explaining how the house is build.

  • Jonathan,

    I have two sections in “JavaFX in Action”, one of which specifically deals with why there are three sets of coordinates (the shape’s own, layoutX/Y and translateX/Y), and another explaining in simple terms what the bounds do.

    Send me an email, and I’ll mail you back the relevant snippets if you want.

  • Hi Jonathan -

    I just posted my blog on JavaFX1.2 bounds, but I attempted to answer your question more directly in the summary:

    http://weblogs.java.net/blog/aim/#chase

    Keep asking good questions. Keeps us honest.

    Aim

Comments are currently closed.

About

Jonathan Giles is a 29 year old software engineer living in Palmerston North, New Zealand. He holds a Bachelor of Engineering Honours in Software Engineering, a Masters of Science in Computer Science, and is a Sun certified Java programmer. Jonathan specialises in Java, Swing, JavaFX and Client-Server development.

He is currently the tech lead at Oracle in the JavaFX UI controls team, and a Java evangelist. He also blogs over at the FX Experience blog. Obviously, the opinions expressed here are his own.

Contact

Email:   Here
NZ:   +64 22 1985 001
Twitter:   JonathanGiles
LinkedIn:   My Profile
Google+:   +JonathanGiles
Skype:   Skype Me