Trying to use baseline alignment in JavaFX can be pretty hard to get
right. For example: put some shape and a label into a layout
container, and the container's baseline might not reflect what you
would intuitively assume (which is the text baseline). In fact, most
layout containers just take the first child that reports a baseline
other than the special constant BASELINE_OFFSET_SAME_AS_HEIGHT and use
that as the baseline for the entire container.

Since there is no meaningful baseline if the first child is not a text
node, the layout container won't neatly align with other kinds of text
or text composites.

Another issue is that the baseline offset of a resizable node depends
on the height of the node, but the height of the node also depends on
the baseline offset. This circular dependency is currently unaccounted
for in controls such as Labeled (that's the reason for bugs like
JDK-809261).

I've prepared a PR that makes working with baseline alignments easier
and more consistent, and also solves the circular dependency problem
by introducing a multi-pass layout algorithm. The PR includes
before-and-after images that help visualize the problem and the
proposed solution.

Here's the PR: https://github.com/openjdk/jfx/pull/433

Reply via email to