JavaFX如何编辑/重命名/更新已添加到组合框的项目

问题描述

对于javafx还是很新的。我有一个组合框,可以在其中通过添加按钮和删除按钮添加和删除项目。但是,我找不到一种方法来编辑已添加到组合框中的那些项目,即将“项目2”更改为“项目b”。 我正在考虑将下拉列表双向绑定到文本字段,以便当从下拉列表中选择一个项目时,该项目将出现在文本字段中,然后可以对其进行编辑(一旦我发现了如何进行绑定)。

@FXML
private ComboBox<String> comboBoxx;

@FXML
private TextField textFieldd;

@FXML
private Button addbutton;

@FXML
private TextField addTextfFeld;

@FXML
private Button renameButton;


ObservableList<String> category = FXCollections.observableArrayList("rock","hip-hop","classical","pop","jazz");

 @Override
public void initialize(URL url,ResourceBundle resourceBundle) {
    comboBoxx.setEditable(true);
    comboBoxx.setItems(category);

}

String categoryValue;
public void addCategoryOnClick(ActionEvent event){
    categoryValue = addTextfFeld.getText();
    if(categoryValue.length() < 1){
        //message saying need to type a category (can just add a label and change that
        
    }else{
        System.out.println("value is" + categoryValue);
        category.add(categoryValue);
    }
}


public ObservableList<String> getCategory() {
    return category;
}

public void setCategory(ObservableList<String> category) {
    this.category = category;
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)