List of usage examples for java.awt Container getComponent
public Component getComponent(int n)
From source file:edu.ku.brc.af.ui.forms.validation.ValSpinner.java
/** * Sets the spinner to the proper color. *///from w ww . j a va 2 s . c o m protected JTextField getTextField(final Container container) { for (int i = 0; i < container.getComponentCount(); i++) { Component c = container.getComponent(i); if (c instanceof JTextField) { return (JTextField) c; } else if (c instanceof Container) { JTextField tf = getTextField((Container) c); if (tf != null) { return tf; } } } return null; }
From source file:XYLayout.java
Dimension getLayoutSize(Container target, boolean doPreferred) { Dimension dim = new Dimension(0, 0); if (width <= 0 || height <= 0) { int count = target.getComponentCount(); for (int i = 0; i < count; i++) { Component component = target.getComponent(i); if (component.isVisible()) { Rectangle r = getComponentBounds(component, doPreferred); dim.width = Math.max(dim.width, r.x + r.width); dim.height = Math.max(dim.height, r.y + r.height); }/*w w w . j a v a 2 s . c o m*/ } } if (width > 0) dim.width = width; if (height > 0) dim.height = height; Insets insets = target.getInsets(); dim.width += insets.left + insets.right; dim.height += insets.top + insets.bottom; return dim; }
From source file:FunLayout.java
public Dimension preferredLayoutSize(Container con) { Component comp;/* w ww .j a v a 2 s . c om*/ Rectangle rect; int i, count; Dimension d; d = new Dimension(0, 0); count = con.countComponents(); for (i = 0; i < count; i++) { comp = con.getComponent(i); if (!comp.isVisible()) continue; rect = comp.getBounds(); if (d.width < rect.x + rect.width) d.width = rect.x + rect.width; if (d.height < rect.y + rect.height) d.height = rect.y + rect.height; } return d; }
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 ww w . ja v a 2 s. c om 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;//from w w w.jav a 2 s. co m //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; } } }
From source file:VerticalLayout.java
/** * Lays out the container./*w w w. j a va 2s . c om*/ */ public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); synchronized (parent.getTreeLock()) { int n = parent.getComponentCount(); Dimension pd = parent.getSize(); int y = 0; //work out the total size for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); Dimension d = c.getPreferredSize(); y += d.height + vgap; } y -= vgap; //otherwise there's a vgap too many //Work out the anchor paint if (anchor == TOP) y = insets.top; else if (anchor == CENTER) y = (pd.height - y) / 2; else y = pd.height - y - insets.bottom; //do layout for (int i = 0; i < n; i++) { Component c = parent.getComponent(i); Dimension d = c.getPreferredSize(); int x = insets.left; int wid = d.width; if (alignment == CENTER) x = (pd.width - d.width) / 2; else if (alignment == RIGHT) x = pd.width - d.width - insets.right; else if (alignment == BOTH) wid = pd.width - insets.left - insets.right; c.setBounds(x, y, wid, d.height); y += d.height + vgap; } } }
From source file:GraphPaperLayout.java
/** * Algorithm for calculating the largest minimum or preferred cell size. * <P>//from w ww.j av a2 s . co m * Largest cell size is calculated by getting the applicable size of each * component and keeping the maximum value, dividing the component's width by * the number of columns it is specified to occupy and dividing the * component's height by the number of rows it is specified to occupy. * * @param parent * the container in which to do the layout. * @param isPreferred * true for calculating preferred size, false for calculating minimum * size. * @return the largest cell size required. */ protected Dimension getLargestCellSize(Container parent, boolean isPreferred) { int ncomponents = parent.getComponentCount(); Dimension maxCellSize = new Dimension(0, 0); for (int i = 0; i < ncomponents; i++) { Component c = parent.getComponent(i); Rectangle rect = compTable.get(c); if (c != null && rect != null) { Dimension componentSize; if (isPreferred) { componentSize = c.getPreferredSize(); } else { componentSize = c.getMinimumSize(); } // Note: rect dimensions are already asserted to be > 0 when the // component is added with constraints maxCellSize.width = Math.max(maxCellSize.width, componentSize.width / rect.width); maxCellSize.height = Math.max(maxCellSize.height, componentSize.height / rect.height); } } return maxCellSize; }
From source file:RadialLayout.java
/** * Sets the sizes attribute of the RadialLayout object. * * @param parent the parent.// w w w . j a va 2 s.c o m * * @see LayoutManager */ private void setSizes(final Container parent) { final int nComps = parent.getComponentCount(); //Reset preferred/minimum width and height. this.preferredWidth = 0; this.preferredHeight = 0; this.minWidth = 0; this.minHeight = 0; for (int i = 0; i < nComps; i++) { final Component c = parent.getComponent(i); if (c.isVisible()) { final Dimension d = c.getPreferredSize(); if (this.maxCompWidth < d.width) { this.maxCompWidth = d.width; } if (this.maxCompHeight < d.height) { this.maxCompHeight = d.height; } this.preferredWidth += d.width; this.preferredHeight += d.height; } } this.preferredWidth = this.preferredWidth / 2; this.preferredHeight = this.preferredHeight / 2; this.minWidth = this.preferredWidth; this.minHeight = this.preferredHeight; }
From source file:GraphPaperTest.java
/** * Algorithm for calculating the largest minimum or preferred cell size. * <p>/*from ww w. j a va 2 s . co m*/ * Largest cell size is calculated by getting the applicable size of each * component and keeping the maximum value, dividing the component's width * by the number of columns it is specified to occupy and dividing the * component's height by the number of rows it is specified to occupy. * * @param parent * the container in which to do the layout. * @param isPreferred * true for calculating preferred size, false for calculating * minimum size. * @return the largest cell size required. */ protected Dimension getLargestCellSize(Container parent, boolean isPreferred) { int ncomponents = parent.getComponentCount(); Dimension maxCellSize = new Dimension(0, 0); for (int i = 0; i < ncomponents; i++) { Component c = parent.getComponent(i); Rectangle rect = (Rectangle) compTable.get(c); if (c != null && rect != null) { Dimension componentSize; if (isPreferred) { componentSize = c.getPreferredSize(); } else { componentSize = c.getMinimumSize(); } // Note: rect dimensions are already asserted to be > 0 when the // component is added with constraints maxCellSize.width = Math.max(maxCellSize.width, componentSize.width / rect.width); maxCellSize.height = Math.max(maxCellSize.height, componentSize.height / rect.height); } } return maxCellSize; }
From source file:CircleLayoutTest.java
public void setSizes(Container parent) { if (sizesSet) return;/*from www . j a v 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; }