问题
I know that you can add Anchor Pane contains in fxml like:'AnchorPane.bottomAnchor="0.0"' but can you set AnchorPane constrains in java code?
回答1:
There are a set of static methods on AnchorPane which you call with the node and the constraint.
- AnchorPane.setTopAnchor(Node, double)
- AnchorPane.setBottomAnchor(Node, double)
- ... etc.
Example
AnchorPane.setBottomAnchor(button, 0.0);
来源:https://stackoverflow.com/questions/28245538/how-to-add-anchor-pane-constrains-in-javafx-code