AnchorPane and border/padding

Nir Lisker nlisker at gmail.com
Tue Jan 27 10:41:39 UTC 2026


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


More information about the openjfx-dev mailing list