Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8097244

[ComboBox, Javadoc] selected item displayed but selection model is empty



      I came across a situation where a non-editable, collapsed combobox would show a selected item but the selection model is empty. Obviously this is inconsistent and leads to subsequent errors when the code thinks nothing is selected while the user sees that something is selected.

      It seems as if there are multiple ways to cause this. I could isolate one of these into a test. The attached demo shows two radiobuttons and a combobox, plus a label which is always updated when a radiobutton is selected. The label shows the currently selected radiobutton and the current combobox selection. See also attached screenshot.

      Consider this sequence:
          cb.getItems().setAll(FXCollections.observableArrayList("E1", "E2", "E3"));

      This will result in a combobox with empty selection model but E1 selected on screen.

      The following sequence fixes it:
          cb.getItems().setAll(FXCollections.observableArrayList("E1", "E2", "E3"));

      It seems necessary to clear the selection before changing the items. As noted before, there must be more ways to cause this because in my real (non-demo) application I could not get away with this workaround. By the way, this seems to be the opposite of RT-24412 which is about not seeing the selection on screen which was made in code.




            • Assignee:
              jgiles Jonathan Giles
              wlehmann Werner Lehmann
            • Votes:
              2 Vote for this issue
              5 Start watching this issue


              • Created: