java.awt.Container#getComponent ( )源码实例Demo

下面列出了java.awt.Container#getComponent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netcdf-java   文件: MFlowLayout.java
public Dimension preferredLayoutSize(Container target) {
  synchronized (target.getTreeLock()) {
    Dimension dim = new Dimension(0, 0);

    for (int i = 0; i < target.getComponentCount(); i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getPreferredSize();

        // original
        // dim.height = Math.max(dim.height, d.height);
        // if (i > 0) { dim.width += hgap; }
        // dim.width += d.width;

        // new way
        Point p = m.getLocation();
        dim.width = Math.max(dim.width, p.x + d.width);
        dim.height = Math.max(dim.height, p.y + d.height);
      }
    }
    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right + getHgap() * 2;
    dim.height += insets.top + insets.bottom + getVgap() * 2;
    return dim;
  }
}
 
源代码2 项目: TencentKona-8   文件: XComponentPeer.java
private void addTree(Collection order, Set set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        ComponentPeer peer = comp.getPeer();
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
源代码3 项目: Spark   文件: VerticalFlowLayout.java
/**
 * places the components defined by first to last within the target
 * container using the bounds box defined.
 *
 * @param target the container.
 * @param x      the x coordinate of the area.
 * @param y      the y coordinate of the area.
 * @param width  the width of the area.
 * @param height the height of the area.
 * @param first  the first component of the container to place.
 * @param last   the last component of the container to place.
 */
private void placethem(Container target, int x, int y, int width, int height,
                       int first, int last) {
    int align = getAlignment();
    if (align == MIDDLE)
        y += height / 2;
    if (align == BOTTOM)
        y += height;

    for (int i = first; i < last; i++) {
        Component m = target.getComponent(i);
        Dimension md = m.getSize();
        if (m.isVisible()) {
            int px = x + (width - md.width) / 2;
            m.setLocation(px, y);
            y += vgap + md.height;
        }
    }
}
 
源代码4 项目: TencentKona-8   文件: JDesktopPane.java
private static Collection<JInternalFrame> getAllFrames(Container parent) {
    int i, count;
    Collection<JInternalFrame> results = new LinkedHashSet<>();
    count = parent.getComponentCount();
    for (i = 0; i < count; i++) {
        Component next = parent.getComponent(i);
        if (next instanceof JInternalFrame) {
            results.add((JInternalFrame) next);
        } else if (next instanceof JInternalFrame.JDesktopIcon) {
            JInternalFrame tmp = ((JInternalFrame.JDesktopIcon) next).getInternalFrame();
            if (tmp != null) {
                results.add(tmp);
            }
        } else if (next instanceof Container) {
            results.addAll(getAllFrames((Container) next));
        }
    }
    return results;
}
 
源代码5 项目: jdk8u_jdk   文件: XComponentPeer.java
private void addTree(Collection order, Set set, Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
        Component comp = cont.getComponent(i);
        ComponentPeer peer = comp.getPeer();
        if (peer instanceof XComponentPeer) {
            Long window = Long.valueOf(((XComponentPeer)peer).getWindow());
            if (!set.contains(window)) {
                set.add(window);
                order.add(window);
            }
        } else if (comp instanceof Container) {
            // It is lightweight container, it might contain heavyweight components attached to this
            // peer
            addTree(order, set, (Container)comp);
        }
    }
}
 
源代码6 项目: Spark   文件: VerticalFlowLayout.java
/**
    * Returns the minimum size needed to layout the target container.
    *
    * @param target the component to lay out.
    * @return the minimum layout dimension.
    */
   @Override
public Dimension minimumLayoutSize(Container target) {
       Dimension tarsiz = new Dimension(0, 0);

       for (int i = 0; i < target.getComponentCount(); i++) {
           Component m = target.getComponent(i);
           if (m.isVisible()) {
               Dimension d = m.getMinimumSize();
               tarsiz.width = Math.max(tarsiz.width, d.width);
               if (i > 0) {
                   tarsiz.height += vgap;
               }
               tarsiz.height += d.height;
           }
       }
       Insets insets = target.getInsets();
       tarsiz.width += insets.left + insets.right + hgap * 2;
       tarsiz.height += insets.top + insets.bottom + vgap * 2;
       return tarsiz;
   }
 
源代码7 项目: opt4j   文件: DialogLayout.java
@Override
public void layoutContainer(Container parent) {

	int divider = getDivider(parent);
	Insets insets = parent.getInsets();

	int w = parent.getWidth() - insets.left - insets.right - divider;
	int x = insets.left;
	int y = insets.top;
	for (int k = 1; k < parent.getComponentCount(); k += 2) {
		Component comp1 = parent.getComponent(k - 1);
		Component comp2 = parent.getComponent(k);
		Dimension d = comp2.getPreferredSize();
		comp1.setBounds(x, y, divider - hGap, d.height);
		comp2.setBounds(x + divider, y, w, d.height);
		y += d.height + vGap;
	}

}
 
源代码8 项目: tn5250j   文件: ENHGridLayout.java
/**
 * Traverses the children and determines row heights and column widths.
 * @param parent the component which needs to be laid out
 * @param min if true, the minimum size is used. Otherwise, the preferred size
 * is used.
 */
protected void getGridSizes(Container parent, boolean min) {
   int ncomponents = parent.getComponentCount();
   if (ncomponents == 0) return;
   int nrows = rows, ncols = cols;
   if (nrows > 0)
       ncols = (ncomponents + nrows - 1) / nrows;
   else
       nrows = (ncomponents + ncols - 1) / ncols;

   row_heights = new int[nrows];
   col_widths = new int[ncols];

   for (int i = 0; i < ncomponents; i++) {
       Component comp = parent.getComponent(i);
      Dimension d = min ? comp.getMinimumSize() :
                   comp.getPreferredSize();

      int row = i / ncols;
      if (d.height > row_heights[row])
         row_heights[row] = d.height;

      int col = i % ncols;
      if (d.width > col_widths[col])
         col_widths[col] = d.width;
   }
}
 
源代码9 项目: openjdk-jdk9   文件: CompactLayout.java
public Dimension getSize(Container parent, boolean minimum) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension d = new Dimension();
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        if (comp instanceof EnableButton) {
            continue;
        }
        Dimension p = (minimum
                       ? comp.getMinimumSize()
                       : comp.getPreferredSize());
        if (horizontal) {
            d.width += p.width;
            if (d.height < p.height) {
                d.height = p.height;
            }
        } else {
            if (d.width < p.width) {
                d.width = p.width;
            }
            d.height += p.height;
        }
    }
    d.width += (insets.left + insets.right);
    d.height += (insets.top + insets.bottom);
    return d;
}
 
源代码10 项目: Bytecoder   文件: SpringLayout.java
public void layoutContainer(Container parent) {
    setParent(parent);

    int n = parent.getComponentCount();
    getConstraints(parent).reset();
    for (int i = 0 ; i < n ; i++) {
        getConstraints(parent.getComponent(i)).reset();
    }

    Insets insets = parent.getInsets();
    Constraints pc = getConstraints(parent);
    abandonCycles(pc.getX()).setValue(0);
    abandonCycles(pc.getY()).setValue(0);
    abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
                                          insets.left - insets.right);
    abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
                                           insets.top - insets.bottom);

    for (int i = 0 ; i < n ; i++) {
        Component c = parent.getComponent(i);
        Constraints cc = getConstraints(c);
        int x = abandonCycles(cc.getX()).getValue();
        int y = abandonCycles(cc.getY()).getValue();
        int width = abandonCycles(cc.getWidth()).getValue();
        int height = abandonCycles(cc.getHeight()).getValue();
        c.setBounds(insets.left + x, insets.top + y, width, height);
    }
}
 
源代码11 项目: jdk8u60   文件: SpringLayout.java
public void layoutContainer(Container parent) {
    setParent(parent);

    int n = parent.getComponentCount();
    getConstraints(parent).reset();
    for (int i = 0 ; i < n ; i++) {
        getConstraints(parent.getComponent(i)).reset();
    }

    Insets insets = parent.getInsets();
    Constraints pc = getConstraints(parent);
    abandonCycles(pc.getX()).setValue(0);
    abandonCycles(pc.getY()).setValue(0);
    abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
                                          insets.left - insets.right);
    abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
                                           insets.top - insets.bottom);

    for (int i = 0 ; i < n ; i++) {
        Component c = parent.getComponent(i);
        Constraints cc = getConstraints(c);
        int x = abandonCycles(cc.getX()).getValue();
        int y = abandonCycles(cc.getY()).getValue();
        int width = abandonCycles(cc.getWidth()).getValue();
        int height = abandonCycles(cc.getHeight()).getValue();
        c.setBounds(insets.left + x, insets.top + y, width, height);
    }
}
 
源代码12 项目: ramus   文件: BaseDialog.java
private void commitTableEditors(Container con) {
    for (int i = 0; i < con.getComponentCount(); i++) {
        if (con.getComponent(i) instanceof Container)
            commitTableEditors((Container) con.getComponent(i));
        final Component container = con.getComponent(i);
        commitComponent(container);
        if (container instanceof JScrollPane) {
            commitComponent(((JScrollPane) container).getViewport()
                    .getView());
        }

    }
}
 
源代码13 项目: netbeans   文件: PanelSupportedFrameworksVisual.java
private void enableComponents(Container root, boolean enabled) {
    root.setEnabled(enabled);
    for (int i = 0; i < root.getComponentCount(); i++) {
        Component child = root.getComponent(i);
        if (child instanceof Container) {
            enableComponents((Container)child, enabled);
        } else {
            child.setEnabled(enabled);
        }
    }
}
 
源代码14 项目: ramus   文件: BaseDialog.java
private void setEditsAction(final Container con) {
      if (con instanceof JSpinner)
          return;

/*
       * if(con instanceof JSplitPane){
 * setEditsAction(((JSplitPane)con).getLeftComponent());
 * setEditsAction(((JSplitPane)con).getRightComponent()); return; }
 */

      for (int i = 0; i < con.getComponentCount(); i++) {
          if (con.getComponent(i) instanceof Container)
              setEditsAction((Container) con.getComponent(i));
          final Component container = con.getComponent(i);
          if (container instanceof JTextField) {
              processTextField((JTextField) container);
          } else if (container instanceof JPasswordField) {
              ((JPasswordField) container).addActionListener(listener);
          }
          if (container instanceof JTextComponent) {
              addUndoFunctions((JTextComponent) container);
          }
          if (container instanceof JList
                  && !(container instanceof JTableHeader)) {
              ((JList) container).addMouseListener(new MouseAdapter() {

                  @Override
                  public void mouseClicked(final MouseEvent e) {
                      if (e.getButton() == MouseEvent.BUTTON1
                              && e.getClickCount() > 1)
                          onOk();
                  }

              });
          }
      }
  }
 
源代码15 项目: openchemlib-js   文件: VerticalFlowLayout.java
/**
 *  Description of the Method
 *
 *@param  target  Description of Parameter
 *@return         Description of the Returned Value
 */
public Dimension minimumLayoutSize(Container target) {
	synchronized (target.getTreeLock()) {
		Dimension dim = new Dimension(0, 0);
		int nmembers = target.getComponentCount();
		boolean firstVisibleComponent = true;

		for (int ii = 0; ii < nmembers; ii++) {
			Component m = target.getComponent(ii);
			if (m.isVisible()) {
				Dimension d = m.getPreferredSize();
				dim.width = Math.max(dim.width, d.width);
				if (firstVisibleComponent) {
					firstVisibleComponent = false;
				}
				else {
					dim.height += _vgap;
				}
				dim.height += d.height;
			}
		}
		Insets insets = target.getInsets();
		dim.width += insets.left + insets.right + _hgap * 2;
		dim.height += insets.top + insets.bottom + _vgap * 2;
		return dim;
	}
}
 
源代码16 项目: jpexs-decompiler   文件: WrapLayout.java
/**
 * Returns the minimum or preferred dimension needed to layout the target
 * container.
 *
 * @param target target to get layout size for
 * @param preferred should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(Container target, boolean preferred) {
    synchronized (target.getTreeLock()) {
        //  Each row must fit with the width allocated to the containter.
        //  When the container width = 0, the preferred width of the container
        //  has not yet been calculated so lets ask for the maximum.

        int targetWidth = target.getSize().width;

        if (targetWidth == 0) {
            targetWidth = Integer.MAX_VALUE;
        }

        int hgap = getHgap();
        int vgap = getVgap();
        Insets insets = target.getInsets();
        int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
        int maxWidth = targetWidth - horizontalInsetsAndGap;

        //  Fit components into the allowed width
        Dimension dim = new Dimension(0, 0);
        int rowWidth = 0;
        int rowHeight = 0;

        int nmembers = target.getComponentCount();

        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);

            if (m.isVisible()) {
                Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

                //  Can't add the component to current row. Start a new row.
                if (rowWidth + d.width > maxWidth) {
                    addRow(dim, rowWidth, rowHeight);
                    rowWidth = 0;
                    rowHeight = 0;
                }

                //  Add a horizontal gap for all components after the first
                if (rowWidth != 0) {
                    rowWidth += hgap;
                }

                rowWidth += d.width;
                rowHeight = Math.max(rowHeight, d.height);
            }
        }

        addRow(dim, rowWidth, rowHeight);

        dim.width += horizontalInsetsAndGap;
        dim.height += insets.top + insets.bottom + vgap * 2;

        //	When using a scroll pane or the DecoratedLookAndFeel we need to
        //  make sure the preferred size is less than the size of the
        //  target containter so shrinking the container size works
        //  correctly. Removing the horizontal gap is an easy way to do this.
        Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

        if (scrollPane != null && target.isValid()) {
            dim.width -= (hgap + 1);
        }

        return dim;
    }
}
 
源代码17 项目: Briss-2.0   文件: WrapLayout.java
/**
 * Returns the minimum or preferred dimension needed to layout the target
 * container.
 *
 * @param target    target to get layout size for
 * @param preferred should preferred size be calculated
 * @return the dimension to layout the target container
 */
private Dimension layoutSize(final Container target, final boolean preferred) {
    synchronized (target.getTreeLock()) {
        // Each row must fit with the width allocated to the containter.
        // When the container width = 0, the preferred width of the
        // container
        // has not yet been calculated so lets ask for the maximum.

        int targetWidth = target.getSize().width;

        if (targetWidth == 0) {
            targetWidth = Integer.MAX_VALUE;
        }

        int hgap = getHgap();
        int vgap = getVgap();
        Insets insets = target.getInsets();
        int horizontalInsetsAndGap = insets.left + insets.right + (hgap * 2);
        int maxWidth = targetWidth - horizontalInsetsAndGap;

        // Fit components into the allowed width

        Dimension dim = new Dimension(0, 0);
        int rowWidth = 0;
        int rowHeight = 0;

        int nmembers = target.getComponentCount();

        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);

            if (m.isVisible()) {
                Dimension d = preferred ? m.getPreferredSize() : m.getMinimumSize();

                // Can't add the component to current row. Start a new row.

                if (rowWidth + d.width > maxWidth) {
                    addRow(dim, rowWidth, rowHeight);
                    rowWidth = 0;
                    rowHeight = 0;
                }

                // Add a horizontal gap for all components after the first

                if (rowWidth != 0) {
                    rowWidth += hgap;
                }

                rowWidth += d.width;
                rowHeight = Math.max(rowHeight, d.height);
            }
        }

        addRow(dim, rowWidth, rowHeight);

        dim.width += horizontalInsetsAndGap;
        dim.height += insets.top + insets.bottom + vgap * 2;

        // When using a scroll pane or the DecoratedLookAndFeel we need to
        // make sure the preferred size is less than the size of the
        // target containter so shrinking the container size works
        // correctly. Removing the horizontal gap is an easy way to do this.

        Container scrollPane = SwingUtilities.getAncestorOfClass(JScrollPane.class, target);

        if (scrollPane != null) {
            dim.width -= (hgap + 1);
        }

        return dim;
    }
}
 
源代码18 项目: jdk8u_jdk   文件: Test6524757.java
private static Component getC(Component component, int index) {
    Container container = (Container) component;
    return container.getComponent(index);
}
 
源代码19 项目: energy2d   文件: MiscUtil.java
private static SpringLayout.Constraints getConstraintsForCell(int r, int c, Container parent, int cols) {
	SpringLayout layout = (SpringLayout) parent.getLayout();
	Component component = parent.getComponent(r * cols + c);
	return layout.getConstraints(component);
}
 
源代码20 项目: pumpernickel   文件: RotatedPanel.java
@Override
public Dimension preferredLayoutSize(Container parent) {
	Component child = parent.getComponent(0);
	Dimension d = child.getPreferredSize();
	return getRotation().transform(d);
}