Here you can find the source of checkHeavyWeightComponents(JTabbedPane tab)
Parameter | Description |
---|---|
tab | tab |
public static void checkHeavyWeightComponents(JTabbedPane tab)
//package com.java2s; /*/*from ww w. j av a 2 s. c om*/ * Copyright 1997-2016 Unidata Program Center/University Corporation for * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307, * support@unidata.ucar.edu. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or (at * your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.awt.Component; import java.awt.Container; import javax.swing.JComponent; import javax.swing.JTabbedPane; public class Main { /** * Walk the components of the tab and toggle the heavyweight components visiblity * * @param tab tab */ public static void checkHeavyWeightComponents(JTabbedPane tab) { Component[] comps = tab.getComponents(); int selectedIdx = tab.getSelectedIndex(); for (int i = 0; i < comps.length; i++) { toggleHeavyWeightComponents(comps[i], i == selectedIdx); } } /** * Walk the tree and set any heavyweight components visibility. * Note: We don't turn off any component that is under the javax.swing package * If we encounter a JTabbedPane then only show the components * that are in the selected tab * * @param comp Component * @param visible On/off */ public static void toggleHeavyWeightComponents(Component comp, boolean visible) { if (!(comp instanceof JComponent)) { if (!comp.getClass().getName().startsWith("javax.swing")) { comp.setVisible(visible); } } if (!(comp instanceof Container)) { return; } Container cont = (Container) comp; if (visible && (cont instanceof JTabbedPane)) { checkHeavyWeightComponents((JTabbedPane) cont); return; } Component[] comps = cont.getComponents(); for (int i = 0; i < comps.length; i++) { Component child = comps[i]; toggleHeavyWeightComponents(child, visible); } } }