diff --git a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java --- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java +++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java @@ -300,6 +300,8 @@ }; } + private boolean listSelectionLock = false; + private ListView createListView() { final ListView listView = new ListView() { @@ -352,10 +354,21 @@ listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE); listView.getSelectionModel().selectedIndexProperty().addListener(new InvalidationListener() { + @Override public void invalidated(Observable o) { + if (listSelectionLock) return; + int index = listView.getSelectionModel().getSelectedIndex(); + comboBox.getSelectionModel().select(index); + updateDisplayNode(); + } + }); + + comboBox.getSelectionModel().selectedItemProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { - int index = listView.getSelectionModel().getSelectedIndex(); - comboBox.getSelectionModel().select(index); - updateDisplayNode(); + T item = comboBox.getSelectionModel().getSelectedItem(); + listSelectionLock = true; + listView.getSelectionModel().clearSelection(); + listView.getSelectionModel().select(item); + listSelectionLock = false; } }); diff --git a/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java b/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java --- a/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java +++ b/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java @@ -806,4 +806,32 @@ System.out.println("cell: " + cell); assertEquals("TO_STRING", cell.getText()); } + + @Test public void test_rt20189() { + comboBox.getItems().addAll("0","1","2","3","4","5","6","7","8","9"); + + Stage stage = new Stage(); + Scene scene = new Scene(comboBox); + stage.setScene(scene); + comboBox.impl_processCSS(true); + comboBox.show(); + + ListView listView = ((ComboBoxListViewSkin)comboBox.getSkin()).getListView(); + SelectionModel sm = listView.getSelectionModel(); + + comboBox.getSelectionModel().select(2); + Object item = sm.getSelectedItem(); + assertEquals("2", item); + assertEquals(2, sm.getSelectedIndex()); + + comboBox.setValue("test"); + item = sm.getSelectedItem(); + assertEquals("test",item); + assertEquals(-1, sm.getSelectedIndex()); + + comboBox.getSelectionModel().select(2); + item = sm.getSelectedItem(); + assertEquals("2", item); + assertEquals(2, sm.getSelectedIndex()); + } }