1
我有一個ComboBox
,它具有以下代碼所示的實現。我面臨的問題是我只能觸發ChangeListener
一次選擇的項目。我想觸發多次,因爲我點擊相同的項目。爲同一項目觸發組合框選擇事件
int lastGridRowPos = 4;
ObservableList<String> options = FXCollections.observableArrayList(
"IdentityFile",
"LocalForward",
"RemoteForward",
"ForwardAgent",
"ForwardX11"
);
ComboBox propertyBox = new ComboBox(options);
propertyBox.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1) {
System.out.println("SELECTED=" + t1);
int rowCounter = getRowCount(grid);
grid.add(new Label(t1), 0, rowCounter + 1);
TextField field = newTextFieldWithIdPrompt(t1.toUpperCase(), "");
grid.add(field, 1, rowCounter + 1);
propertyBox.getSelectionModel().clearSelection();
}
});
我試圖用propertyBox.getSelectionModel().clearSelection();
但它不工作以清除選擇,這樣我可以在同一項目再次點擊(希望組合框看到了項目的變化)。
感謝您的解決方案(我仍然必須嘗試在我的情況)。現在,當你說出這些話時,我想知道爲什麼菜單不適合我。我會看看菜單。我想要做的就是提供一個供用戶選擇的物品清單,他可以從哪裏允許他們一次又一次地選擇相同的物品。 – summerNight