diff --git a/modules/javafx.controls/src/main/java/javafx/scene/control/ChoiceBox.java b/modules/javafx.controls/src/main/java/javafx/scene/control/ChoiceBox.java index a865beeb95..4dd9a12be5 100644 --- a/modules/javafx.controls/src/main/java/javafx/scene/control/ChoiceBox.java +++ b/modules/javafx.controls/src/main/java/javafx/scene/control/ChoiceBox.java @@ -583,6 +583,11 @@ public class ChoiceBox extends Control { */ @Override public void select(int index) { // this does not sound right, we should let the superclass handle it. + final T value = getModelItem(index); + if (value instanceof Separator || value instanceof SeparatorMenuItem) { + return; + } + super.select(index); if (choiceBox.isShowing()) { @@ -596,7 +601,7 @@ public class ChoiceBox extends Control { int index = getSelectedIndex() - 1; while (index >= 0) { final T value = getModelItem(index); - if (value instanceof Separator) { + if (value instanceof Separator || value instanceof SeparatorMenuItem) { index--; } else { select(index); @@ -611,7 +616,22 @@ public class ChoiceBox extends Control { int index = getSelectedIndex() + 1; while (index < getItemCount()) { final T value = getModelItem(index); - if (value instanceof Separator) { + if (value instanceof Separator || value instanceof SeparatorMenuItem) { + index++; + } else { + select(index); + break; + } + } + } + + /** {@inheritDoc} */ + @Override public void selectFirst() { + // overridden to properly handle Separators + int index = 0; + while (index < getItemCount()) { + final T value = getModelItem(index); + if (value instanceof Separator || value instanceof SeparatorMenuItem) { index++; } else { select(index); @@ -619,6 +639,21 @@ public class ChoiceBox extends Control { } } } + + /** {@inheritDoc} */ + @Override public void selectLast() { + // overridden to properly handle Separators + int index = getItemCount() - 1; + while (index >= 0) { + final T value = getModelItem(index); + if (value instanceof Separator || value instanceof SeparatorMenuItem) { + index--; + } else { + select(index); + break; + } + } + } } /***************************************************************************