Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

LabeledSkinBase ignores contract of prefWidth for graphic #646

Open
hjohn opened this issue Feb 4, 2021 · 0 comments
Open

LabeledSkinBase ignores contract of prefWidth for graphic #646

hjohn opened this issue Feb 4, 2021 · 0 comments

Comments

@hjohn
Copy link
Contributor

hjohn commented Feb 4, 2021

LabeledSkinBase contains this code in computePrefWidth:

    // Fix for RT-39889
    double graphicWidth = graphic == null ? 0.0 :
            Utils.boundedSize(graphic.prefWidth(-1), graphic.minWidth(-1), graphic.maxWidth(-1));

It calls here (out of the blue) some methods to compute widths for the graphic. However, when using a graphic which has a vertical content bias, calling this with -1 violates the contract of prefWidth (and others). From the docs of prefWidth:

 Layout code which calls this method should first check the content-bias
 of the node.  If the node has a vertical content-bias, then callers
 should pass in a height value that the preferred width should be based on.
 If the node has either a horizontal or null content-bias, then the caller
 should pass in -1.

The result is that the wrong width is computed for the graphic and the button (or whatever is using LabeledSkinBase) will become too wide and leave some empty space that is hard to explain.

Putting the exact same objects in an HBox (a graphic and a label) yields the expected results. One might wonder why LabeledSkinBase reinvents the wheel here.

An attempt was made to solve this by overriding the computePrefWidth method to do a proper calculation. but this runs into problems with package private fields which the subclass can't access.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant