List of usage examples for java.awt Container getComponentCount
public int getComponentCount()
From source file:CircleLayoutTest.java
public void setSizes(Container parent) { if (sizesSet) return;// w ww . j a va 2 s .co m int comCount = parent.getComponentCount(); for (int i = 0; i < comCount; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension size = c.getPreferredSize(); maxComponentWidth = Math.max(maxComponentWidth, size.width); maxComponentHeight = Math.max(maxComponentWidth, size.height); preferredHeight += size.height; } } preferredHeight += maxComponentHeight; preferredWidth = 2 * maxComponentWidth; minHeight = preferredHeight; minWidth = preferredWidth; sizesSet = true; }
From source file:CenterLayout.java
public void layoutContainer(Container container) { int count = container.getComponentCount(); if (count > 0) { Component child = container.getComponent(0); java.awt.Insets insets = container.getInsets(); int availWidth = container.getWidth() - insets.left - insets.right; int availHeight = container.getHeight() - insets.top - insets.bottom; Dimension preferredSize = child.getPreferredSize(); double preferredWidth = preferredSize.getWidth(); double preferredHeight = preferredSize.getHeight(); int width; int height; int x;/* www.j av a 2s .c o m*/ int y; if (preferredWidth < availWidth) { x = (int) Math.round(insets.left + (availWidth - preferredWidth) / 2); width = (int) Math.round(preferredWidth); } else { x = insets.left; width = availWidth; } if (preferredHeight < availHeight) { y = (int) Math.round(insets.top + (availHeight - preferredHeight) / 2); height = (int) Math.round(preferredHeight); } else { y = insets.top; height = availHeight; } child.setBounds(x, y, width, height); } }
From source file:WrapperLayout.java
public Dimension preferredLayoutSize(Container arg0) { java.awt.Insets insets = arg0.getInsets(); int count = arg0.getComponentCount(); if (count > 0) { Dimension d = arg0.getComponent(0).getPreferredSize(); return new Dimension(d.width + insets.left + insets.right, d.height + insets.top + insets.bottom); } else {/*from w ww . ja v a2s . c om*/ return new Dimension(insets.left + insets.right, insets.top + insets.bottom); } }
From source file:WrapperLayout.java
public Dimension minimumLayoutSize(Container arg0) { java.awt.Insets insets = arg0.getInsets(); int count = arg0.getComponentCount(); if (count > 0) { Dimension d = arg0.getComponent(0).getMinimumSize(); return new Dimension(d.width + insets.left + insets.right, d.height + insets.top + insets.bottom); } else {/*from w w w . j a va2 s. co m*/ return new Dimension(insets.left + insets.right, insets.top + insets.bottom); } }
From source file:SquareLayout.java
/** * Returns the sole child of the specified container, or <code>null</code> if * none. Throws an <code>IllegalStateException</code> if there is more than * one child./* w ww . j av a2s . com*/ */ private Component getChild(Container c) { int childCount = c.getComponentCount(); if (childCount > 1) throw new IllegalStateException("May not layout more than one component"); else if (childCount == 0) return null; else return c.getComponent(childCount - 1); }
From source file:net.sf.nmedit.jtheme.component.misc.CallDescriptor.java
private JTComponent getTarget() { if (target == null) { Container c = owner.getParent(); if (c != null) { for (int i = c.getComponentCount() - 1; i >= 0; i--) { Component t = c.getComponent(i); if (t instanceof JTComponent && component.equals(t.getName())) { target = (JTComponent) t; break; }//w ww. ja va2s .c o m } } } return target; }
From source file:CircleLayoutTest.java
public void setSizes(Container parent) { if (sizesSet) return;/*from w w w .j av a 2 s .c o m*/ int n = parent.getComponentCount(); preferredWidth = 0; preferredHeight = 0; minWidth = 0; minHeight = 0; maxComponentWidth = 0; maxComponentHeight = 0; // compute the maximum component widths and heights // and set the preferred size to the sum of the component sizes. for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); maxComponentWidth = Math.max(maxComponentWidth, d.width); maxComponentHeight = Math.max(maxComponentHeight, d.height); preferredWidth += d.width; preferredHeight += d.height; } } minWidth = preferredWidth / 2; minHeight = preferredHeight / 2; sizesSet = true; }
From source file:CircleLayoutDemo.java
/** * Arranges the parent's Component objects in either an Ellipse or a Circle. * Ellipse is not yet implemented./*from w w w . ja v a 2 s. c om*/ */ public void layoutContainer(Container parent) { int x, y, w, h, s, c; int n = parent.getComponentCount(); double parentWidth = parent.getSize().width; double parentHeight = parent.getSize().height; Insets insets = parent.getInsets(); int centerX = (int) (parentWidth - (insets.left + insets.right)) / 2; int centerY = (int) (parentHeight - (insets.top + insets.bottom)) / 2; Component comp = null; Dimension compPS = null; if (n == 1) { comp = parent.getComponent(0); x = centerX; y = centerY; compPS = comp.getPreferredSize(); w = compPS.width; h = compPS.height; comp.setBounds(x, y, w, h); } else { double r = (Math.min(parentWidth - (insets.left + insets.right), parentHeight - (insets.top + insets.bottom))) / 2; r *= 0.75; // Multiply by .75 to account for extreme right and bottom // Components for (int i = 0; i < n; i++) { comp = parent.getComponent(i); compPS = comp.getPreferredSize(); if (isCircle) { c = (int) (r * Math.cos(2 * i * Math.PI / n)); s = (int) (r * Math.sin(2 * i * Math.PI / n)); } else { c = (int) ((centerX * 0.75) * Math.cos(2 * i * Math.PI / n)); s = (int) ((centerY * 0.75) * Math.sin(2 * i * Math.PI / n)); } x = c + centerX; y = s + centerY; w = compPS.width; h = compPS.height; comp.setBounds(x, y, w, h); } } }
From source file:ColumnLayout.java
protected Dimension layoutSize(Container parent, int sizetype) { int nkids = parent.getComponentCount(); Dimension size = new Dimension(0, 0); Insets insets = parent.getInsets(); int num_visible_kids = 0; // Compute maximum width and total height of all visible kids for (int i = 0; i < nkids; i++) { Component kid = parent.getComponent(i); Dimension d;/*from w w w. j a va 2 s .c o m*/ if (!kid.isVisible()) continue; num_visible_kids++; if (sizetype == 1) d = kid.getPreferredSize(); else if (sizetype == 2) d = kid.getMinimumSize(); else d = kid.getMaximumSize(); if (d.width > size.width) size.width = d.width; size.height += d.height; } // Now add in margins and stuff size.width += insets.left + insets.right + 2 * margin_width; size.height += insets.top + insets.bottom + 2 * margin_height; if (num_visible_kids > 1) size.height += (num_visible_kids - 1) * spacing; return size; }
From source file:Main.java
private void setSizes(Container parent) { int nComps = parent.getComponentCount(); Dimension d = null;/* w w w.j av a 2 s . c om*/ //Reset preferred/minimum width and height. preferredWidth = 0; preferredHeight = 0; minWidth = 0; minHeight = 0; for (int i = 0; i < nComps; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { d = c.getPreferredSize(); if (i > 0) { preferredWidth += d.width / 2; preferredHeight += vgap; } else { preferredWidth = d.width; } preferredHeight += d.height; minWidth = Math.max(c.getMinimumSize().width, minWidth); minHeight = preferredHeight; } } }