changeset 1288:6e34b405d07e

RT-22326: TabPane: unable to select the following tab when a tab is closed.
author Kinsley Wong
date Tue, 12 Jun 2012 14:30:53 -0700
parents 8192bc3aa019
children 9d72813b0448
files javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TabPaneBehavior.java javafx-ui-controls/src/javafx/scene/control/TabPane.java javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java
diffstat 3 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TabPaneBehavior.java	Tue Jun 12 10:39:55 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TabPaneBehavior.java	Tue Jun 12 14:30:53 2012 -0700
@@ -145,7 +145,7 @@
         if (tab.isSelected()) {
             if (index == 0) {
                 if (tabPane.getTabs().size() > 1) {
-                    tabPane.getSelectionModel().selectFirst();
+                    tabPane.getSelectionModel().clearSelection();
                 }
             } else {
                 tabPane.getSelectionModel().selectPrevious();
--- a/javafx-ui-controls/src/javafx/scene/control/TabPane.java	Tue Jun 12 10:39:55 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TabPane.java	Tue Jun 12 14:30:53 2012 -0700
@@ -636,6 +636,7 @@
                                     tab.setSelected(false);
                                     if (c.getFrom() == 0) {
                                         if (tabPane.getTabs().size() > 1) {
+                                            clearSelection();
                                             selectFirst();
                                         }
                                     } else {
--- a/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Tue Jun 12 10:39:55 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Tue Jun 12 14:30:53 2012 -0700
@@ -708,4 +708,22 @@
         tk.firePulse();        
         assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
     }
+    
+    @Test public void unableToSelectNextTabWhenFirstTabIsClosed_RT22326() {
+        tabPane.getTabs().add(tab1);
+        tabPane.getTabs().add(tab2);
+        tabPane.getTabs().add(tab3);
+
+        assertEquals("one", tabPane.getTabs().get(0).getText());
+        assertEquals("two", tabPane.getTabs().get(1).getText());
+        assertEquals("three", tabPane.getTabs().get(2).getText());
+        
+        tabPane.getTabs().remove(tab1);
+
+        assertEquals(2, tabPane.getTabs().size());
+        assertEquals(0, tabPane.getSelectionModel().getSelectedIndex());
+        assertEquals(tab2, tabPane.getSelectionModel().getSelectedItem());
+        tabPane.getSelectionModel().selectNext();
+        assertEquals(tab3, tabPane.getSelectionModel().getSelectedItem());
+    }
 }