[External] : Re: AnchorPane and border/padding

Andy Goryachev andy.goryachev at oracle.com
Tue Jan 27 18:44:51 UTC 2026


I've updated https://bugs.openjdk.org/browse/JDK-8350809 since it seems related.

Thanks!

-andy


From: Nir Lisker <nlisker at gmail.com>
Date: Tuesday, January 27, 2026 at 10:22
To: Andy Goryachev <andy.goryachev at oracle.com>
Cc: openjfx-dev <openjfx-dev at openjdk.org>
Subject: [External] : Re: AnchorPane and border/padding

You're right that it's the null constraints. I would have expected
them to still respect borders and padding. This definitely needs to be
documented.

On Tue, Jan 27, 2026 at 6:37 PM Andy Goryachev
<andy.goryachev at oracle.com> wrote:
>
> In other words, the case you are describing is not a bug, though we probably should document the behavior when no anchors are set on a child.
>
> -andy
>
>
> From: openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of Andy Goryachev <andy.goryachev at oracle.com>
> Date: Tuesday, January 27, 2026 at 08:33
> To: Nir Lisker <nlisker at gmail.com>, openjfx-dev <openjfx-dev at openjdk.org>
> Subject: Re: AnchorPane and border/padding
>
> Nir:
>
> I think the problem is that the AnchorPane fails to handle null constraints, see for example https://bugs.openjdk.org/browse/JDK-8350809
>
> In your example, try setting non-null anchor, like so
> https://urldefense.com/v3/__https://github.com/andy-goryachev-oracle/Test/blob/9796540833c2430bec8f5aca9584faa2ffb7cc7f/src/goryachev/bugs/AnchorPane_WithBorders.java*L24__;Iw!!ACWV5N9M2RV99hQ!O2KtfC3vI7UcebSWAftl2R62sFBi4QOCMUPd-006BSEERW4dJcowGSx74Pt82gCVNmIgjbTJDfOuISrDf1Fb$
>
> -andy
>
>
>
> From: openjfx-dev <openjfx-dev-retn at openjdk.org> on behalf of Nir Lisker <nlisker at gmail.com>
> Date: Tuesday, January 27, 2026 at 02:42
> To: openjfx-dev <openjfx-dev at openjdk.org>
> Subject: AnchorPane and border/padding
>
> Hi,
>
> I've encountered what I think is a bug in AnchorPane. When setting a
> border and/or padding, any added children will be laid out on top of
> them rather than computing the anchor points from them. The
> documentation states "If the anchor pane has a border and/or padding
> set, the offsets will be measured from the inside edge of those
> insets."
>
> The test program gives a different result:
>
> public class TestApplication extends Application {
>
> public static void main(String[] args) {
> launch(TestApplication.class, args);
> }
>
> @Override
> public void start(Stage primaryStage) throws Exception {
> var pane = new AnchorPane();
> pane.setBorder(new Border(new BorderStroke(Color.BLUE,
> BorderStrokeStyle.SOLID, null, new BorderWidths(6))));
> pane.setPadding(new Insets(10));
> pane.setBackground(Background.fill(Color.grayRgb(256/4, 0.8)));
>
> pane.setMaxHeight(100);
> pane.setMaxWidth(100);
> pane.setMinHeight(100);
> pane.setMinWidth(100);
>
> Rectangle rect = new Rectangle(40, 40);
> rect.setFill(Color.AQUA);
> pane.getChildren().add(rect);
>
> primaryStage.setScene(new Scene(new BorderPane(pane), 300, 200));
> primaryStage.show();
> }
> }
>
> The rectangle comes out on top of the border and insets. When using
> TilePane, FlowPane, and HBox, these are respected. The closest issue I
> found is https://bugs.openjdk.org/browse/JDK-8090844 .
>
> I would say that the documentation is correct and AnchorPane's
> behavior is wrong, but I find it odd that it hasn't come up until now.
>
> - Nir
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20260127/f05a3b1c/attachment.htm>


More information about the openjfx-dev mailing list