Calculating the preferred size of a node before layout takes place?
tomas.mikula at gmail.com
Mon Aug 4 20:34:43 UTC 2014
If you are interested in the preferred height, prefHeight(-1) should
get you what you want. If this is before the first layout pass takes
place, you will also want to call applyCss() before prefHeight(-1).
Note: prefHeight(-1) is what autosize() calls internally, but it does
not call applyCss().
On Mon, Aug 4, 2014 at 9:29 PM, Jeff Martin <jeff at reportmill.com> wrote:
> I was thinking that certain nodes (e.g., TextField) won’t provide a valid pref size until the window was made visible (and the CSS had been evaluated).
> A few times I’ve added code set Window Opacity to zero, do a Window show/hide, then reset Window Opacity to one. Then you should get valid pref sizes. I’m not proud of myself, but it seems to work in practice. :-)
> On Aug 4, 2014, at 1:03 PM, Richard Bair <richard.bair at oracle.com> wrote:
>> autosize() on Node may be what you want (sizes it then afterward you can read values)?
>> On Aug 4, 2014, at 10:56 AM, Mike Hearn <mike at plan99.net> wrote:
>>> I'd like to find the calculated height of a node in my window controllers
>>> initialise() method, so I can shrink the height to zero and then animate it
>>> to the right size later. However getHeight and getPrefHeight both return
>>> zero in this method, presumably because it's not been laid out yet.
>>> I tried calling layout() but that didn't help.
>>> I don't want any visual glitches caused by a node being visible and then
>>> immediately resized to invisibility. Is there a solution to my problem? I
>>> feel there must be an obvious one that I'm just overlooking somehow ...
More information about the openjfx-dev