1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
983
984 /* if the selected tab is the last tab */
985 } else if (selected >= getTabCount()) {
986 setSelectedIndexImpl(selected - 1, false);
987 Page newSelected = (selected != 0)
988 ? pages.get(selected - 1)
989 : null;
990
991 changeAccessibleSelection(null, oldName, newSelected);
992
993 /* selected index hasn't changed, but the associated tab has */
994 } else if (index == selected) {
995 fireStateChanged();
996 changeAccessibleSelection(null, oldName, pages.get(index));
997 }
998
999 // We can't assume the tab indices correspond to the
1000 // container's children array indices, so make sure we
1001 // remove the correct child!
1002 if (component != null) {
1003 Component components[] = getComponents();
1004 for (int i = components.length; --i >= 0; ) {
1005 if (components[i] == component) {
1006 super.remove(i);
1007 component.setVisible(true);
1008 break;
1009 }
1010 }
1011 }
1012
1013 if (shouldChangeFocus) {
1014 SwingUtilities2.tabbedPaneChangeFocusTo(getSelectedComponent());
1015 }
1016
1017 revalidate();
1018 repaint();
1019 }
1020
1021 /**
1022 * Removes the specified <code>Component</code> from the
1023 * <code>JTabbedPane</code>. The method does nothing
1024 * if the <code>component</code> is null.
1025 *
1026 * @param component the component to remove from the tabbedpane
1027 * @see #addTab
1028 * @see #removeTabAt
1029 */
1030 public void remove(Component component) {
1031 int index = indexOfComponent(component);
1032 if (index != -1) {
1033 removeTabAt(index);
1034 } else {
1035 // Container#remove(comp) invokes Container#remove(int)
1036 // so make sure JTabbedPane#remove(int) isn't called here
1037 Component children[] = getComponents();
1038 for (int i=0; i < children.length; i++) {
1039 if (component == children[i]) {
1040 super.remove(i);
1041 break;
1042 }
1043 }
1044 }
1045 }
1046
1047 /**
1048 * Removes the tab and component which corresponds to the specified index.
1049 *
1050 * @param index the index of the component to remove from the
1051 * <code>tabbedpane</code>
1052 * @exception IndexOutOfBoundsException if index is out of range
1053 * {@code (index < 0 || index >= tab count)}
1054 * @see #addTab
1055 * @see #removeTabAt
1056 */
1057 public void remove(int index) {
1531 * {@code (index < 0 || index >= tab count)}
1532 *
1533 * @see #getComponentAt
1534 */
1535 @BeanProperty(visualUpdate = true, description
1536 = "The component at the specified tab index.")
1537 @SuppressWarnings("deprecation")
1538 public void setComponentAt(int index, Component component) {
1539 Page page = pages.get(index);
1540 if (component != page.component) {
1541 boolean shouldChangeFocus = false;
1542
1543 if (page.component != null) {
1544 shouldChangeFocus =
1545 (SwingUtilities.findFocusOwner(page.component) != null);
1546
1547 // REMIND(aim): this is really silly;
1548 // why not if (page.component.getParent() == this) remove(component)
1549 synchronized(getTreeLock()) {
1550 int count = getComponentCount();
1551 Component children[] = getComponents();
1552 for (int i = 0; i < count; i++) {
1553 if (children[i] == page.component) {
1554 super.remove(i);
1555 }
1556 }
1557 }
1558 }
1559
1560 page.component = component;
1561 boolean selectedPage = (getSelectedIndex() == index);
1562
1563 if (selectedPage) {
1564 this.visComp = component;
1565 }
1566
1567 if (component != null) {
1568 component.setVisible(selectedPage);
1569 addImpl(component, null, -1);
1570
1571 if (shouldChangeFocus) {
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
983
984 /* if the selected tab is the last tab */
985 } else if (selected >= getTabCount()) {
986 setSelectedIndexImpl(selected - 1, false);
987 Page newSelected = (selected != 0)
988 ? pages.get(selected - 1)
989 : null;
990
991 changeAccessibleSelection(null, oldName, newSelected);
992
993 /* selected index hasn't changed, but the associated tab has */
994 } else if (index == selected) {
995 fireStateChanged();
996 changeAccessibleSelection(null, oldName, pages.get(index));
997 }
998
999 // We can't assume the tab indices correspond to the
1000 // container's children array indices, so make sure we
1001 // remove the correct child!
1002 if (component != null) {
1003 Component[] components = getComponents();
1004 for (int i = components.length; --i >= 0; ) {
1005 if (components[i] == component) {
1006 super.remove(i);
1007 component.setVisible(true);
1008 break;
1009 }
1010 }
1011 }
1012
1013 if (shouldChangeFocus) {
1014 SwingUtilities2.tabbedPaneChangeFocusTo(getSelectedComponent());
1015 }
1016
1017 revalidate();
1018 repaint();
1019 }
1020
1021 /**
1022 * Removes the specified <code>Component</code> from the
1023 * <code>JTabbedPane</code>. The method does nothing
1024 * if the <code>component</code> is null.
1025 *
1026 * @param component the component to remove from the tabbedpane
1027 * @see #addTab
1028 * @see #removeTabAt
1029 */
1030 public void remove(Component component) {
1031 int index = indexOfComponent(component);
1032 if (index != -1) {
1033 removeTabAt(index);
1034 } else {
1035 // Container#remove(comp) invokes Container#remove(int)
1036 // so make sure JTabbedPane#remove(int) isn't called here
1037 Component[] children = getComponents();
1038 for (int i=0; i < children.length; i++) {
1039 if (component == children[i]) {
1040 super.remove(i);
1041 break;
1042 }
1043 }
1044 }
1045 }
1046
1047 /**
1048 * Removes the tab and component which corresponds to the specified index.
1049 *
1050 * @param index the index of the component to remove from the
1051 * <code>tabbedpane</code>
1052 * @exception IndexOutOfBoundsException if index is out of range
1053 * {@code (index < 0 || index >= tab count)}
1054 * @see #addTab
1055 * @see #removeTabAt
1056 */
1057 public void remove(int index) {
1531 * {@code (index < 0 || index >= tab count)}
1532 *
1533 * @see #getComponentAt
1534 */
1535 @BeanProperty(visualUpdate = true, description
1536 = "The component at the specified tab index.")
1537 @SuppressWarnings("deprecation")
1538 public void setComponentAt(int index, Component component) {
1539 Page page = pages.get(index);
1540 if (component != page.component) {
1541 boolean shouldChangeFocus = false;
1542
1543 if (page.component != null) {
1544 shouldChangeFocus =
1545 (SwingUtilities.findFocusOwner(page.component) != null);
1546
1547 // REMIND(aim): this is really silly;
1548 // why not if (page.component.getParent() == this) remove(component)
1549 synchronized(getTreeLock()) {
1550 int count = getComponentCount();
1551 Component[] children = getComponents();
1552 for (int i = 0; i < count; i++) {
1553 if (children[i] == page.component) {
1554 super.remove(i);
1555 }
1556 }
1557 }
1558 }
1559
1560 page.component = component;
1561 boolean selectedPage = (getSelectedIndex() == index);
1562
1563 if (selectedPage) {
1564 this.visComp = component;
1565 }
1566
1567 if (component != null) {
1568 component.setVisible(selectedPage);
1569 addImpl(component, null, -1);
1570
1571 if (shouldChangeFocus) {
|