changeset 5999:a6dbe9cc05a0

RT-35013: A SplitPane used inside a TabPane is not being rendered until I resize the Stage
author jgiles
date Thu, 19 Dec 2013 12:19:03 +1300
parents 6cb6225e0708
children 6ec6a557a2c4
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TabPaneSkin.java modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java
diffstat 2 files changed, 34 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TabPaneSkin.java	Wed Dec 18 13:35:41 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TabPaneSkin.java	Thu Dec 19 12:19:03 2013 +1300
@@ -33,7 +33,6 @@
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.beans.property.DoubleProperty;
-import javafx.beans.property.DoublePropertyBase;
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleDoubleProperty;
 import javafx.collections.FXCollections;
@@ -49,7 +48,6 @@
 import javafx.event.EventHandler;
 import javafx.geometry.Bounds;
 import javafx.geometry.HPos;
-import javafx.geometry.Point2D;
 import javafx.geometry.Pos;
 import javafx.geometry.Side;
 import javafx.geometry.VPos;
@@ -79,10 +77,8 @@
 import javafx.util.Duration;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 import com.sun.javafx.css.converters.EnumConverter;
 import com.sun.javafx.scene.control.MultiplePropertyChangeListenerHandler;
 import com.sun.javafx.scene.control.behavior.TabPaneBehavior;
@@ -561,11 +557,6 @@
             // see RT-29167
             tabContent.resize(contentWidth, contentHeight);
             tabContent.relocate(contentStartX, contentStartY);
-            
-            Node content = tabContent.getTab().getContent();
-            if (content != null) {
-                content.setVisible(tabContent.getTab().equals(selectedTab));
-            }
         }
     }
     
@@ -1438,7 +1429,7 @@
         private Direction direction = Direction.NEXT;
         //private Direction direction;
         private Tab tab;
-        private InvalidationListener tabListener;
+        private InvalidationListener tabContentListener;
 
         public Tab getTab() {
             return tab;
@@ -1450,31 +1441,15 @@
             this.tab = tab;
             updateContent();
 
-            tabListener = new InvalidationListener() {
-                @Override public void invalidated(Observable valueModel) {
-                    if (valueModel == getTab().selectedProperty()) {
-                        setVisible(getTab().isSelected());
-                    } else if (valueModel == getTab().contentProperty()) {
-                        getChildren().clear();
-                        updateContent();
-                    }
-                }
-            };
-            tab.selectedProperty().addListener(new InvalidationListener() {
-                @Override public void invalidated(Observable valueModel) {
-                    setVisible(getTab().isSelected());
-                }
-            });
-            tab.contentProperty().addListener(new InvalidationListener() {
+            visibleProperty().bind(tab.selectedProperty());
+
+            tab.contentProperty().addListener(tabContentListener = new InvalidationListener() {
                 @Override public void invalidated(Observable valueModel) {
                     getChildren().clear();
                     updateContent();
                 }
             });
 
-            tab.selectedProperty().addListener(tabListener);
-            tab.contentProperty().addListener(tabListener);
-
             engine = new TraversalEngine(this, false) {
                 @Override public void trav(Node owner, Direction dir) {
                     direction = dir;
@@ -1483,18 +1458,19 @@
             };
             engine.addTraverseListener(this);
             setImpl_traversalEngine(engine);
-            setVisible(tab.isSelected());
         }
 
         private void updateContent() {
-            if (getTab().getContent() != null) {
-                getChildren().add(getTab().getContent());
+            if (getTab().getContent() == null) {
+                getChildren().clear();
+            } else {
+                getChildren().setAll(getTab().getContent());
             }
         }
 
         private void removeListeners(Tab tab) {
-            tab.selectedProperty().removeListener(tabListener);
-            tab.contentProperty().removeListener(tabListener);
+            visibleProperty().unbind();
+            tab.contentProperty().removeListener(tabContentListener);
             engine.removeTraverseListener(this);
         }
 
--- a/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Wed Dec 18 13:35:41 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TabPaneTest.java	Thu Dec 19 12:19:03 2013 +1300
@@ -34,6 +34,8 @@
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
+
+import com.sun.javafx.scene.control.infrastructure.StageLoader;
 import javafx.application.Platform;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
@@ -850,5 +852,26 @@
 
         assertTrue(button1Focused);
 
-    }    
+    }
+
+    @Test public void test_rt_35013() {
+        SplitPane splitPane = new SplitPane();
+        splitPane.getItems().addAll(new Button("Button1"), new Button("Button2"));
+
+        TabPane tabPane = new TabPane();
+        Tab emptyTab;
+        Tab splitTab = new Tab("SplitPane Tab");
+        splitTab.setContent(splitPane);
+        tabPane.getTabs().addAll(emptyTab = new Tab("Empty Tab"), splitTab);
+
+        new StageLoader(tabPane);
+
+        tabPane.getSelectionModel().select(emptyTab);
+        Toolkit.getToolkit().firePulse();
+        assertFalse(splitPane.getParent().isVisible());
+
+        tabPane.getSelectionModel().select(splitTab);
+        Toolkit.getToolkit().firePulse();
+        assertTrue(splitPane.getParent().isVisible());
+    }
 }