changeset 2238:692177a0af9d

fix RT-25008 ChoiceBox: if the second item is selected by default "IndexOutOfBoundsException" is reported.
author Paru Somashekar <paru.somashekar@oracle.com>
date Mon, 14 Jan 2013 17:19:08 -0800
parents 4ffc6d741427
children 800fa5f31489
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ContextMenuContent.java javafx-ui-controls/test/javafx/scene/control/ChoiceBoxTest.java
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Mon Jan 14 15:27:45 2013 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Mon Jan 14 17:19:08 2013 -0800
@@ -763,7 +763,7 @@
      */
     double getMenuYOffset(int menuIndex) {
         double offset = 0;
-        if (itemsContainer.getChildren().size() >= menuIndex) {
+        if (itemsContainer.getChildren().size() > menuIndex) {
             offset = getInsets().getTop();
             Node menuitem = itemsContainer.getChildren().get(menuIndex);
             offset += menuitem.getLayoutY() + menuitem.prefHeight(-1);
--- a/javafx-ui-controls/test/javafx/scene/control/ChoiceBoxTest.java	Mon Jan 14 15:27:45 2013 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/ChoiceBoxTest.java	Mon Jan 14 17:19:08 2013 -0800
@@ -407,4 +407,13 @@
         startApp(pane);
         assertEquals(0, box.getItems().size());
     }
+    
+     @Test public void testSelectingItemBeforeFirstShow() {
+        StackPane pane = new StackPane();
+        pane.getChildren().add(box);
+        box.getItems().addAll("Apple", "Orange", "Banana");
+        box.getSelectionModel().select("Orange");
+        startApp(pane);
+        assertEquals(1, box.getSelectionModel().getSelectedIndex());
+    }
 }