我对 Java 有点陌生,我正在尝试在 JavaFX 中创建一个用户界面,每当用户按下“+”按钮时,它就会动态添加一个 TextField 和一个“编辑”按钮。我知道尝试将这些按钮和文本字段存储在列表中是个好主意,但我不确定如何将它们放在界面上
ListView<Button> dinamicButtons = new ListView<Button>();
ListView<TextField> dinamicTextFields = new ListView<TextField>();
int quantityOfDinamicFieldsAdded =0;
Button add= new Button ("+");
add.setOnAction(e -> {
dinamicButtons .add(quantityOfDinamicFieldsAdded , new Button("Edit"));
dinamicTextFields .add(quantityOfDinamicFieldsAdded , new TextField("nome do Componente"));
quantityOfDinamicFieldsAdded ++;
//remove dynamically added buttons and text fields
for (int i=0 ; i<quantityOfDinamicFieldsAdded ; i++){
//add them all back
}
});
繁星点点滴滴
相关分类