我有两个问题
1.在JavaFX应用程序中,我想将子项(crosshairArea)放置在其父项的左上角,同时宽度和高度为其父项的1/2。 我认为可以通过覆盖父类函数“layoutChildren”(VBox)来实现, 还有其他方式吗?例如属性绑定?
2.最初,VBox将占用整个场景区域,如何使(重新定位)其位于场景的下半部分?
public class Crossh extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
VBox root = new VBox(5);
// root.setPadding(new Insets(20,20,20,20));
root.setStyle("-fx-border-color:red");
Pane crosshairArea = new Pane();
crosshairArea.maxWidthProperty().bind(root.widthProperty());
crosshairArea.setStyle("-fx-border-color:black");
root.getChildren().add(crosshairArea);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Location Crosshair");
stage.setWidth(900);
stage.setHeight(700);
stage.show();
}
}
VBox.setVgrow(child, Priority.ALWAYS);
对我非常有效。 - ManoDestra