Jugaccino

Gaming News | Gaming Opinion | Playstation 4 | Xbox One | PS Vita | Film | Media

JavaFX – AnchorPane


The article will provide a user with information on AnchorPane. The AnchorPane layout pane enables a user to anchor nodes to the top, bottom, left side, right side, or center of the pane. As the window is resized, the nodes maintain their position relative to their anchor point. Nodes can be anchored to more than one position and more than one node can be anchored to the same position.

Let’s see how to create an anchor pane with a node anchored to the top of the pane and a node anchored to the bottom right of the pane.

AnchorPane anchorpane = new AnchorPane();
Button buttonSave = new Button(“Save”);
Button buttonCancel = new Button(“Cancel”);

HBox hbox = new HBox();
hbox.setPadding(new Insets(0, 10, 10, 10));
hbox.setSpacing(10);
hbox.getChildren().addAll(buttonSave, buttonCancel);

anchorpane.getChildren().addAll(grid,hbox); // Add grid from Example 5
AnchorPane.setBottomAnchor(hbox, 8.0);
AnchorPane.setRightAnchor(hbox, 5.0);
AnchorPane.setTopAnchor(grid, 10.0);

border.setCenter(anchorpane);

As the window is resized, the nodes maintain their position in the pane according to their anchor points.

If a user has read the article then he/she would have learnt about anchor pane and also how to create an anchor pane.

Be Sociable, Share!

Leave a Comment