java.awt.Container.getComponentCount()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(236)

本文整理了Java中java.awt.Container.getComponentCount()方法的一些代码示例,展示了Container.getComponentCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Container.getComponentCount()方法的具体详情如下:
包路径:java.awt.Container
类名称:Container
方法名:getComponentCount

Container.getComponentCount介绍

[英]Gets the number of components in this panel.
[中]获取此面板中的组件数。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-util

/** Find a focus-traverable component.
* @param c the component to look in
* @return the same component if traversable, else a child component if present, else <code>null</code>
* @see Component#isFocusTraversable
*/
public static Component getFocusTraversableComponent(Component c) {
  if (c.isFocusable()) {
    return c;
  }
  if (!(c instanceof Container)) {
    return null;
  }
  int i;
  int k = ((Container) c).getComponentCount();
  for (i = 0; i < k; i++) {
    Component v = ((Container) c).getComponent(i);
    if (v != null) {
      return v;
    }
  }
  return null;
}

代码示例来源:origin: stackoverflow.com

Insets insets = target.getInsets();
if (insets == null){
 insets = new Insets(0, 0, 0, 0);
int n = target.getComponentCount();
int x = 0;
int y = insets.top + vgap; // FlowLayout starts by adding vgap, so do that here too.
 Component c = target.getComponent(i);
 if (c.isVisible()) {
   Dimension d = c.getPreferredSize();
   if ((x == 0) || ((x + d.width) <= maxwidth)) {
int miny = Integer.MIN_VALUE;
boolean found_one = false;
int n = target.getComponentCount();
 Component c = target.getComponent(i);
 if (c.isVisible()) {
   found_one = true;
   Dimension d = c.getPreferredSize();
   minx = Math.min(minx, d.width);
   miny = Math.min(miny, d.height);

代码示例来源:origin: runelite/runelite

final int ncomponents = parent.getComponentCount();
int nrows = getRows();
int ncols = getColumns();
  final Component comp = parent.getComponent(i);
  final Dimension d = sizer.apply(comp);
final Insets insets = parent.getInsets();

代码示例来源:origin: org.netbeans.api/org-openide-awt

private int getMaximumWidth(Container target) {
  int maxWidth = 0;
  synchronized (target.getTreeLock()) {
    int nmembers = target.getComponentCount();
    for (int i = 0; i < nmembers; i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getPreferredSize();
        maxWidth = Math.max(d.width, maxWidth);
      }
    }
  }
  return maxWidth;
}

代码示例来源:origin: stackoverflow.com

super.addImpl(comp, constraints, index);
if(maximumVisibleRows < getComponentCount()-1) {
  getScrollBar().setVisible(true);
if(maximumVisibleRows >= getComponentCount()-1) {
  getScrollBar().setVisible(false);
  for(Component comp : getComponents()) {
    if(!(comp instanceof JScrollBar)) {
      Dimension preferredSize = comp.getPreferredSize();
      width = Math.max(width, preferredSize.width);
      if(unit < 0){
        Dimension pref = comp.getPreferredSize();
        dim.width = Math.max(dim.width, pref.width);
        dim.height += pref.height;
  Insets insets = parent.getInsets();
  dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount);
  Insets insets = parent.getInsets();
  dim.height = Math.min(dim.height + insets.top + insets.bottom, visibleAmount);
  Insets insets = parent.getInsets();

代码示例来源:origin: com.harium.propan/propan-jogl

@Override
public Dimension preferredLayoutSize(Container parent) {
 if (parent.isPreferredSizeSet() || parent.getComponentCount() == 0) {
  return parent.getPreferredSize();
 } else {
  int x = -1, y = -1;
  for (Component child : parent.getComponents()) {
   Dimension dim = child.getPreferredSize();
   x = Math.max(dim.width, x);
   y = Math.max(dim.height, y);
  }
  return new Dimension(x, y);
 }
}

代码示例来源:origin: stackoverflow.com

return (popupMenu == null) ? 0 : popupMenu.getComponentCount();
return (popupMenu == null) ? null : popupMenu.getComponent(n);

代码示例来源:origin: eu.mihosoft.vrl/vrl

@Override
public Dimension minimumLayoutSize(Container parent) {
  Dimension dim = new Dimension(0, 0);
  int nComps = parent.getComponentCount();
  //Always add the container's insets!
  Insets insets = parent.getInsets();
  dim.width = minWidth + insets.left + insets.right;
  dim.height = minHeight + insets.top + insets.bottom;
  sizeUnknown = false;
  return dim;
}

代码示例来源:origin: runelite/runelite

final Insets insets = parent.getInsets();
final int ncomponents = parent.getComponentCount();
int nrows = getRows();
int ncols = getColumns();
  final Component comp = parent.getComponent(i);
  final Dimension d = comp.getPreferredSize();
  d.width = (int) (sw * d.width);
  d.height = (int) (sh * d.height);
      parent.getComponent(i).setBounds(x, y, w[c], h[r]);

代码示例来源:origin: crashinvaders/gdx-texture-packer-gui

public Dimension preferredLayoutSize (Container parent) {
  Dimension size = new Dimension();
  for (int i = 0, n = parent.getComponentCount(); i < n; i++) {
    Dimension pref = parent.getComponent(i).getPreferredSize();
    size.width = Math.max(size.width, pref.width);
    size.height = Math.max(size.height, pref.height);
  }
  return size;
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * @return returns true if the component of one of its child has the focus
 */
public static boolean isAncestorOfFocusedComponent(Component c) {
  if (c.hasFocus()) {
    return true;
  } else {
    if (c instanceof Container) {
      Container cont = (Container) c;
      int n = cont.getComponentCount();
      for (int i = 0; i < n; i++) {
        Component child = cont.getComponent(i);
        if (isAncestorOfFocusedComponent(child))
          return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: magefree/mage

private Dimension getLayoutSize(Container parent, int type) {
  int width = 0;
  int height = 0;
  int components = parent.getComponentCount();
  int visibleComponents = getVisibleComponents(parent);
  for (int i = 0; i < components; i++) {
    Component component = parent.getComponent(i);
    if (!component.isVisible()) {
      continue;
    }
    Dimension d = getDimension(component, type);
    if (axis == X_AXIS) {
      width += d.width;
      height = Math.max(height, d.height);
    } else {
      width = Math.max(width, d.width);
      height += d.height;
    }
  }
  Insets insets = parent.getInsets();
  int totalGap = ((visibleComponents - 1) * gap) + (2 * borderGap);
  if (axis == X_AXIS) {
    width += insets.left + insets.right + totalGap;
    height += insets.top + insets.bottom;
  } else {
    width += insets.left + insets.right;
    height += insets.top + insets.bottom + totalGap;
  }
  return new Dimension(width, height);
}

代码示例来源:origin: brandonborkholder/glg2d

@Override
public Dimension preferredLayoutSize(Container parent) {
 if (parent.isPreferredSizeSet() || parent.getComponentCount() == 0) {
  return parent.getPreferredSize();
 } else {
  int x = -1, y = -1;
  for (Component child : parent.getComponents()) {
   Dimension dim = child.getPreferredSize();
   x = Math.max(dim.width, x);
   y = Math.max(dim.height, y);
  }
  return new Dimension(x, y);
 }
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

@Override
public Dimension preferredLayoutSize(Container parent) {
  Dimension dim = new Dimension(0, 0);
  int nComps = parent.getComponentCount();
  setSizes(parent);
  //Always add the container's insets!
  Insets insets = parent.getInsets();
  dim.width = preferredWidth + insets.left + insets.right;
  dim.height = preferredHeight + insets.top + insets.bottom;
  sizeUnknown = false;
  return dim;
}

代码示例来源:origin: pengwei1024/AndroidSourceViewer

@Override
  public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    int maxWidth = parent.getWidth() - (insets.left + insets.right);
    int count = parent.getComponentCount();
    int height = 0;
    int gap = padding;
    for (int i = 0; i < count; i++) {
      Component component = parent.getComponent(i);
      if (component.isVisible()) {
        Dimension size = component.getPreferredSize();
        component.setBounds(gap, height, maxWidth - gap * 2, size.height);
        height += size.height + gap * 2;
      }
    }
  }
}

代码示例来源:origin: tahaemara/object-recognition-tensorflow

public Dimension preferredLayoutSize (Container parent) {
  Dimension size = new Dimension();
  for (int i = 0, n = parent.getComponentCount(); i < n; i++) {
    Dimension pref = parent.getComponent(i).getPreferredSize();
    size.width = Math.max(size.width, pref.width);
    size.height = Math.max(size.height, pref.height);
  }
  return size;
}

代码示例来源:origin: igniterealtime/Openfire

int n = cont.getComponentCount();
for (int i = 0; i < n; i++) {
  Component child = cont.getComponent(i);
  Component focused = getFocusableComponentOrChild(child, deepest);
  if (focused != null) {

代码示例来源:origin: org.netbeans.api/org-openide-awt

synchronized (target.getTreeLock()) {
  Dimension dim = new Dimension(0, 0);
  int nmembers = target.getComponentCount();
    Component m = target.getComponent(i);
  Insets insets = target.getInsets();
  dim.width += (insets.left + insets.right + (getHgap() * 2));
  dim.height += (insets.top + insets.bottom + (getVgap() * 2));

代码示例来源:origin: pengwei1024/AndroidSourceViewer

@Override
public Dimension preferredLayoutSize(Container target) {
  synchronized (target.getTreeLock()) {
    Dimension dim = new Dimension(0, 0);
    int count = target.getComponentCount();
    for (int i = 0; i < count; i++) {
      Component m = target.getComponent(i);
      Dimension d = m.getPreferredSize();
      dim.width = Math.max(dim.width, d.width);
      dim.height += d.height + padding;
    }
    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right + padding * 2;
    dim.height += insets.top + insets.bottom + padding * 2;
    return dim;
  }
}

代码示例来源:origin: org.jclarion/clarion-runtime

@Override
public Dimension preferredLayoutSize(Container parent) 
{
  int maxHeight=0;
  int width=0;
  for (int scan=0;scan<parent.getComponentCount();scan++) {
    Component base = parent.getComponent(scan);
    Dimension pref = base.getPreferredSize();
    if (sizes[scan]>0) {
      width+=sizes[scan];
    } else {
      width-=sizes[scan];
    }
    if (pref.height>maxHeight) maxHeight=pref.height;
  }
  return new Dimension(width,maxHeight);
}

相关文章

微信公众号

最新文章

更多

Container类方法