本文整理汇总了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;
}
}
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
}
示例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
}
}
示例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);
}
}
}
}
示例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()));
}
}
示例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);
}
}
示例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
}
}
}