< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/skin/TabPaneSkin.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -475,28 +475,10 @@
                 tabRegion.isClosing = true;
 
                 tabRegion.removeListeners(tab);
                 removeTabContent(tab);
 
-                // remove the menu item from the popup menu
-                ContextMenu popupMenu = tabHeaderArea.controlButtons.popup;
-                TabMenuItem tabItem = null;
-                if (popupMenu != null) {
-                    for (MenuItem item : popupMenu.getItems()) {
-                        tabItem = (TabMenuItem) item;
-                        if (tab == tabItem.getTab()) {
-                            break;
-                        }
-                        tabItem = null;
-                    }
-                }
-                if (tabItem != null) {
-                    tabItem.dispose();
-                    popupMenu.getItems().remove(tabItem);
-                }
-                // end of removing menu item
-
                 EventHandler<ActionEvent> cleanup = ae -> {
                     tabRegion.animationState = TabAnimationState.NONE;
 
                     tabHeaderArea.removeTab(tab);
                     tabHeaderArea.requestLayout();

@@ -1846,11 +1828,11 @@
             // to hide it animate it back it.
             if (isShowTabsMenu()) {
                 showControlButtons = true;
             } else {
                 setVisible(false);
-                popup.getItems().clear();
+                clearPopupMenu();
                 popup = null;
             }
 
             // This needs to be called when we are in the left tabPosition
             // to allow for the clip offset to move properly (otherwise

@@ -1860,11 +1842,11 @@
 
         private void setupPopupMenu() {
             if (popup == null) {
                 popup = new ContextMenu();
             }
-            popup.getItems().clear();
+            clearPopupMenu();
             ToggleGroup group = new ToggleGroup();
             ObservableList<RadioMenuItem> menuitems = FXCollections.<RadioMenuItem>observableArrayList();
             for (final Tab tab : getSkinnable().getTabs()) {
                 TabMenuItem item = new TabMenuItem(tab);
                 item.setToggleGroup(group);

@@ -1872,10 +1854,17 @@
                 menuitems.add(item);
             }
             popup.getItems().addAll(menuitems);
         }
 
+        private void clearPopupMenu() {
+            for (MenuItem item : popup.getItems()) {
+                ((TabMenuItem) item).dispose();
+            }
+            popup.getItems().clear();
+        }
+
         private void showPopupMenu() {
             for (MenuItem mi: popup.getItems()) {
                 TabMenuItem tmi = (TabMenuItem)mi;
                 if (selectedTab.equals(tmi.getTab())) {
                     tmi.setSelected(true);

@@ -1909,11 +1898,13 @@
         public Tab getTab() {
             return tab;
         }
 
         public void dispose() {
+            textProperty().unbind();
             tab.disableProperty().removeListener(weakDisableListener);
+            tab = null;
         }
     }
 
     @Override
     public Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters) {
< prev index next >