Combobox clearing value issue

前端 未结 8 2593
逝去的感伤
逝去的感伤 2020-12-15 06:00

I\'ve stumbled on an issue with Comboboxes in javafx2.2. This is the scenario:

  • Users click on the \'editFile\' button.
  • Another pane becomes visible (w
8条回答
  •  感动是毒
    2020-12-15 06:23

    I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:

    cboVet.getSelectionModel().clearSelection();
    cboVet.getItems.clear();
    

    do something like this...

    parentNode.getChildren().remove(cboVet);
    cboVet = new ComboBox();  // do whatever else you need to format your ComboBox
    parentNode.add(cboVet);
    

    You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.

提交回复
热议问题