AnchorPane and border/padding

Andy Goryachev andy.goryachev at oracle.com
Tue Jan 27 16:37:06 UTC 2026


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://github.com/andy-goryachev-oracle/Test/blob/9796540833c2430bec8f5aca9584faa2ffb7cc7f/src/goryachev/bugs/AnchorPane_WithBorders.java#L24

-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/4c172452/attachment-0001.htm>


More information about the openjfx-dev mailing list