JavaFX - ScrollPane/VBox - 自动收缩
JavaFX - ScrollPane/VBox - Auto shrink
我正在为孩子们开发一个 JavaFX 应用程序来控制一个小机器人,孩子们会通过 Drag-n-Drops 命令块来定义命令。
目标区域是带有 VBox 的 Scrollpane。
我想知道是否有任何方法可以使 ScrollPane 和 VBox 自动调整大小,因此当我将一个节点添加到绿色块时它必须增长(已经在做)并且当我从绿色块中删除一个节点时它必须收缩。
代码如下:
// Set to BorderPane#Center<br/>
boxCode = new VBox(0.0);
boxCode.setMinSize(400, 80);
// here I also set MaxSize using Double.MAX_VALUE and USE_COMPUTED_SIZE
paneCode = new ScrollPane(boxCode);
paneCode.setMinSize(400, 80);
paneCode.setStyle("-fx-background-color:transparent;");
paneCode.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
layout.setCenter(paneCode);
带有节点的 VBox:
没有节点的 VBox:
这是我的项目:GitHub - Programming Block
谢谢!
我不太确定我是否理解这个问题。当我像下面的示例一样为 VBox
和 ScrollPane
设置 minHeight 时,它对我有用。
public void start(Stage primaryStage) {
Button btnAdd = new Button("add");
Button btnRemove = new Button("remove");
VBox box = new VBox(btnAdd, btnRemove);
box.setStyle("-fx-border-color:red");
btnAdd.setOnAction(e -> box.getChildren().add(new Label("test")));
btnRemove.setOnAction(e -> {
int idx = box.getChildren().size();
box.getChildren().remove(idx - 1);
});
ScrollPane scrollPane = new ScrollPane(box);
scrollPane.setMinHeight(200);
box.setMinHeight(200) ;
BorderPane root = new BorderPane(scrollPane);
primaryStage.setScene(new Scene(root, 300, 300));
primaryStage.show();
}
我正在为孩子们开发一个 JavaFX 应用程序来控制一个小机器人,孩子们会通过 Drag-n-Drops 命令块来定义命令。 目标区域是带有 VBox 的 Scrollpane。
我想知道是否有任何方法可以使 ScrollPane 和 VBox 自动调整大小,因此当我将一个节点添加到绿色块时它必须增长(已经在做)并且当我从绿色块中删除一个节点时它必须收缩。
代码如下:
// Set to BorderPane#Center<br/>
boxCode = new VBox(0.0);
boxCode.setMinSize(400, 80);
// here I also set MaxSize using Double.MAX_VALUE and USE_COMPUTED_SIZE
paneCode = new ScrollPane(boxCode);
paneCode.setMinSize(400, 80);
paneCode.setStyle("-fx-background-color:transparent;");
paneCode.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
layout.setCenter(paneCode);
带有节点的 VBox:
没有节点的 VBox:
这是我的项目:GitHub - Programming Block
谢谢!
我不太确定我是否理解这个问题。当我像下面的示例一样为 VBox
和 ScrollPane
设置 minHeight 时,它对我有用。
public void start(Stage primaryStage) {
Button btnAdd = new Button("add");
Button btnRemove = new Button("remove");
VBox box = new VBox(btnAdd, btnRemove);
box.setStyle("-fx-border-color:red");
btnAdd.setOnAction(e -> box.getChildren().add(new Label("test")));
btnRemove.setOnAction(e -> {
int idx = box.getChildren().size();
box.getChildren().remove(idx - 1);
});
ScrollPane scrollPane = new ScrollPane(box);
scrollPane.setMinHeight(200);
box.setMinHeight(200) ;
BorderPane root = new BorderPane(scrollPane);
primaryStage.setScene(new Scene(root, 300, 300));
primaryStage.show();
}