當前位置: 首頁>>代碼示例>>Java>>正文


Java Container.getComponents方法代碼示例

本文整理匯總了Java中java.awt.Container.getComponents方法的典型用法代碼示例。如果您正苦於以下問題:Java Container.getComponents方法的具體用法?Java Container.getComponents怎麽用?Java Container.getComponents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Container的用法示例。


在下文中一共展示了Container.getComponents方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: layoutContainer

import java.awt.Container; //導入方法依賴的package包/類
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    int posX = insets.left;
    final int posY = insets.top;
    final int height = parent.getHeight() - insets.top - insets.bottom;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible()) {
            Dimension pref = comp.getPreferredSize();
            if (proportionalHeight) {
                int h = Math.min(pref.height, height);
                int o = (height - h) / 2;
                comp.setBounds(posX, posY + o, pref.width, h);
            } else {
                comp.setBounds(posX, posY, pref.width, height);
            }
            posX += hGap;
            posX += pref.width;
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:HorizontalLayout.java

示例2: findNotificationLabel

import java.awt.Container; //導入方法依賴的package包/類
private static JLabel findNotificationLabel (Container container) {
    for (Component component : container.getComponents ()) {
        if (component.getClass ().getName ().indexOf (NOTIFICATION_LABEL_NAME) != -1) {
            return (JLabel) component;
        }
        if (component instanceof JRootPane) {
            JRootPane rp = (JRootPane) component;
            return findNotificationLabel (rp.getContentPane ());
        }
        if (component instanceof JPanel) {
            JPanel p = (JPanel) component;
            return findNotificationLabel (p);
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:NotificationLineSupportTest.java

示例3: layoutContainer

import java.awt.Container; //導入方法依賴的package包/類
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    final int posX = insets.left;
    int posY = insets.top;
    final int width = parent.getWidth() - insets.left - insets.right;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible()) {
            Dimension pref = comp.getPreferredSize();
            if (proportionalWidth) {
                int w = Math.min(pref.width, width);
                int o = (width - w) / 2;
                comp.setBounds(posX, posY + o, w, pref.height);
            } else {
                comp.setBounds(posX, posY, width, pref.height);
            }
            pref.height += vGap;
            posY += pref.height;
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:VerticalLayout.java

示例4: find

import java.awt.Container; //導入方法依賴的package包/類
private static Component find(Component c, Class<?> clazz, boolean fail) {
    if (clazz.isInstance(c)) {
        return c;
    }
    if (c instanceof Container) {
        Container cont = (Container)c;
        for (Component p : cont.getComponents()) {
            Component r = find(p, clazz, false);
            if (r != null) {
                return r;
            }
        }
    }
    if (fail) {
        fail("Not found " + clazz + " in children of " + c);
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:19,代碼來源:TemplatesPanelGUITest.java

示例5: findComponent

import java.awt.Container; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static <T> T findComponent(Container container, Class<T> componentClass, int depth) {
    if (depth > 0) {
        for (Component c : container.getComponents()) {
            if (componentClass.isAssignableFrom(c.getClass())) {
                return (T) c;
            } else if (c instanceof Container) {
                T target = findComponent((Container) c, componentClass, depth - 1);
                if (target != null) {
                    return target;
                }
            }
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:SearchNbEditorKit.java

示例6: preferredLayoutSize

import java.awt.Container; //導入方法依賴的package包/類
public Dimension preferredLayoutSize(final Container parent) {
    final Insets insets = parent.getInsets();
    final Dimension d = new Dimension(insets.left + insets.right,
                                      insets.top + insets.bottom);
    int maxWidth = 0;
    int visibleCount = 0;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible()) {
            final Dimension size = comp.getPreferredSize();
            maxWidth = Math.max(maxWidth, size.width);
            d.height += size.height;
            visibleCount++;
        }
    }

    d.height += (visibleCount - 1) * vGap;
    d.width += maxWidth;

    return d;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:22,代碼來源:VerticalLayout.java

示例7: evalSize

import java.awt.Container; //導入方法依賴的package包/類
private Dimension evalSize(Container parent, boolean min) {
	synchronized (parent.getTreeLock()) {
		int w = 0, h = 0;
		int nrows = 1, ncols = 1;
		int row = 0, col = 0;
		// eval max size and rows/cols
		for (Component cmp : parent.getComponents())
			if (cmp.isVisible()) {
				ncols = col + 1;
				if (row >= nrows)
					nrows = row + 1;
				// eval size
				Dimension d = min ? cmp.getMinimumSize() : cmp
						.getPreferredSize();
				if (w < d.width)
					w = d.width;
				if (h < d.height)
					h = d.height;
				// eval matrix
				if (++row >= getRows()) {
					row = 0;
					col++;
				}
			}
		// add insets
		Insets insets = parent.getInsets();
		return new Dimension(insets.left + insets.right + ncols * w
				+ (ncols - 1) * getHgap(), insets.top + insets.bottom
				+ nrows * h + (nrows - 1) * getVgap());
	}
}
 
開發者ID:KeepTheBeats,項目名稱:alevin-svn2,代碼行數:32,代碼來源:MyGridLayout.java

示例8: enableComponent

import java.awt.Container; //導入方法依賴的package包/類
public static void enableComponent(Container con, boolean state, Component component) {
    for (Component c : con.getComponents()) {
        if (c instanceof Container) {
            enableComponent((Container) c, state, component);
        }
        if (component != null && component.equals(c)) {
            continue;
        }
        if (c instanceof JLabel) {
            c.setVisible(state);
        } else {
            c.setEnabled(state);
        }
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:16,代碼來源:Utility.java

示例9: getIndexOfComponentInParent

import java.awt.Container; //導入方法依賴的package包/類
private int getIndexOfComponentInParent(Component component) {
    Container parent = component.getParent();
    if (parent == null) {
        return -1;
    }
    Component[] components = parent.getComponents();
    for (int i = 0; i < components.length; i++) {
        if (components[i] == component) {
            return i;
        }
    }
    return -1;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:14,代碼來源:GeneralSiblingSelector.java

示例10: layoutContainer

import java.awt.Container; //導入方法依賴的package包/類
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:15,代碼來源:MetalworksPrefs.java

示例11: detachFromHierarchyOf

import java.awt.Container; //導入方法依賴的package包/類
private void detachFromHierarchyOf(Container container) {
    container.removeContainerListener(this);
    Component[] components = container.getComponents();
    for (int i = 0; i < components.length; i++) {
        detachFrom(components[i]); // Will callback recursively any nested JPanels
    }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:8,代碼來源:GenericListener.java

示例12: getFrames

import java.awt.Container; //導入方法依賴的package包/類
/**
 * Adds all {@code JEditorPanes} under {@code container} tagged by {@code
 * FrameEditorPaneTag} to the {@code list}. It adds only top
 * level {@code JEditorPanes}.  For instance if there is a frame
 * inside the frame it will return the top frame only.
 *
 * @param c the container to find all frames under
 * @param list {@code List} to append the results too
 */
private static void getFrames(final Container container, List<JEditorPane> list) {
    for (Component c : container.getComponents()) {
        if (c instanceof FrameEditorPaneTag
            && c instanceof JEditorPane ) { //it should be always JEditorPane
            list.add((JEditorPane) c);
        } else {
            if (c instanceof Container) {
                getFrames((Container) c, list);
            }
        }
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:TextComponentPrintable.java

示例13: layoutContainer

import java.awt.Container; //導入方法依賴的package包/類
@Override
public void layoutContainer(Container parent) {
    StyledDocument doc = (StyledDocument)editor.getDocument();
    for (Component comp : parent.getComponents()) {
        Position pos = positions.get(comp);
        int line = findLineNumber(doc, pos.getOffset());
        Dimension prefSize = comp.getPreferredSize();
        int dy = lineHeight() - prefSize.height;
        dy = dy > 0 ? dy / 2 + 1 : 0;
        comp.setBounds(LEFT_GAP,
                       line * lineHeight() + dy,
                       parent.getWidth() - LEFT_GAP - RIGHT_GAP,
                       Math.min(prefSize.height, lineHeight()));
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:CustomCodeView.java

示例14: handleMouseOver

import java.awt.Container; //導入方法依賴的package包/類
private void handleMouseOver( Container c, MouseListener ml ) {
    c.addMouseListener(ml);
    for( Component child : c.getComponents() ) {
        child.addMouseListener(ml);
        if( child instanceof Container )
            handleMouseOver((Container)child, ml);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:BalloonManager.java

示例15: show

import java.awt.Container; //導入方法依賴的package包/類
public static void show(Container container, String indent) {
    out((container.isShowing() ? "[[ " : "") + indent + container.getClass().getName()); // NOI18N
    Component[] children = container.getComponents();

    for (Component child : children) {
        if (child instanceof Container) {
            show((Container) child, "    " + indent); // NOI18N
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:UI.java


注:本文中的java.awt.Container.getComponents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。