Node and prefWidthProperty

Richard Bair richard.bair at oracle.com
Mon Feb 11 07:42:48 PST 2013


Yes! In fact there is no prefWidth property on Node (no getPrefWidth, setPrefWidth, or prefWidthProperty). Rather the prefWidth() method is a computational method vs. an accessor.

If you look at Region, you will find prefWidthProperty(), getPrefWidth(), and setPrefWidth (along with min width, max width, min height, max height, etc).

The prefWidth() method will inspect the prefWidth property, minWidth property, maxWidth property etc and compute what the pref width for this node is at this time.

Now, perhaps the question could be, why don't we have a computedPrefWidth property on node? I suspect it has to do with two things. First, the bindings associated with such a thing on a layout container would be pretty intense. That's not necessarily saying it couldn't be done ("its all software" as Hans Muller used to say -- we can do anything -- for a price). However I expect it would be difficult. The second reason is because we want to make it easy for subclasses to override the computation of the prefWidth (as each layout container for example have their own algorithm for figuring this out). As such, having method to override is much simpler than binding that has to be broken and reestablished (although again, not impossible).

I'm guessing what you're wanting is a way to know when the pref size has changed?

Richard

On Feb 10, 2013, at 9:58 AM, Sven Reimers <sven.reimers at gmail.com> wrote:

> Hi all,
> 
> any special reason why there is not a prefWidthProperty on Node, although
> it has a prefWidth?
> 
> Thanks
> 
> -Sven
> 
> -- 
> Sven Reimers
> 
> * Senior Expert Software Architect
> * NetBeans Dream Team Member: http://dreamteam.netbeans.org
> * Community Leader  NetBeans: http://community.java.net/netbeans
>                              Desktop Java:
> http://community.java.net/javadesktop
> * Duke's Choice Award Winner 2009
> * Blog: http://nbguru.blogspot.com
> 
> * XING: https://www.xing.com/profile/Sven_Reimers8
> * LinkedIn: http://www.linkedin.com/in/svenreimers
> 
> Join the NetBeans Groups:
> * XING: http://www.xing.com/group-20148.82db20
> * NUGM: http://haug-server.dyndns.org/display/NUGM/Home
> * LinkedIn: http://www.linkedin.com/groups?gid=1860468
>                   http://www.linkedin.com/groups?gid=107402
>                   http://www.linkedin.com/groups?gid=1684717
> * Oracle: https://mix.oracle.com/groups/18497



More information about the openjfx-dev mailing list