点击增加按钮后实现红框内容增加一行。如何实现,希望有简单的demo,第一次用FX。我是基于fxml开发的。
可以采用Vbox布局
https://www.yiibai.com/javafx/javafx_vbox.html,看最后一个例子就行。
这是我程序中添加的代码,我是结合VBox和HBox一起使用的。你自己要根据自己的需求来。
//点击添加时间
@FXML
void addtimecustom(MouseEvent event) {
//理论上来说,下面这种方式应该也是可以的,但是不知道为什么就是出不来效果
//AnchorPane time1 = new AnchorPane(timecustom);
//timebox.getChildren().add(time1);
HBox timeall = new HBox();
TextField time = new TextField();
time.setPrefHeight(6.0);
time.setPrefWidth(40.0);
time.setLayoutY(2.0);
timeall.getChildren().add(time);
Label time1 = new Label(" : ");
time1.setLayoutX(53.0);
time1.setLayoutY(-2.0);
time1.prefHeight(28.0);
time1.setPrefWidth(19.0);
timeall.getChildren().add(time1);
TextField time2 = new TextField();
time2.setPrefHeight(6.0);
time2.setPrefWidth(40.0);
time2.setLayoutY(2.0);
timeall.getChildren().add(time2);
timebox.setSpacing(10.0);
timebox.getChildren().add(timeall);
}
效果: