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 <[email protected]> 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 <[email protected]> on behalf of Andy Goryachev > <[email protected]> > Date: Tuesday, January 27, 2026 at 08:33 > To: Nir Lisker <[email protected]>, openjfx-dev <[email protected]> > 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 <[email protected]> on behalf of Nir Lisker > <[email protected]> > Date: Tuesday, January 27, 2026 at 02:42 > To: openjfx-dev <[email protected]> > 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
