当前位置: 首页>>代码示例>>Java>>正文


Java Container.getSize方法代码示例

本文整理汇总了Java中java.awt.Container.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java Container.getSize方法的具体用法?Java Container.getSize怎么用?Java Container.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Container的用法示例。


在下文中一共展示了Container.getSize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
public void layoutContainer(Container parent) {
    int c = parent.getComponentCount();
    
    Insets insets = parent.getInsets();
    Dimension size = parent.getSize();
    size.width = Math.min(size.width, maximumLayoutSize(parent).width);
    
    int x = insets.left;
    int y = insets.top;
    int w = size.width - x - insets.right - HGAP * (c - 1);
    int h = size.height - y - insets.bottom;
    
    int m = w % c;
    w /= c;

    for (int i = 0; i < c; i++) {
        int o = i < m ? 1 : 0;
        parent.getComponent(i).setBounds(x, y, w + o, h);
        x += w + o + HGAP;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:SnapshotsWindowUI.java

示例2: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container parent) {
	Dimension size = parent.getSize();
	Insets insets = parent.getInsets();
	int itop = insets.top;
	int ileft = insets.left;
	int ibottom = insets.bottom;
	int iright = insets.right;

	int rightWidth = right.getPreferredSize().width;
	int bottomHeight = bottom.getPreferredSize().height;
	int centerWidth = size.width - rightWidth - ileft - iright;
	int centerHeight = size.height - bottomHeight - itop - ibottom;

	center.setBounds(ileft, itop, centerWidth, centerHeight);

	right.setBounds(ileft + centerWidth, itop, rightWidth, centerHeight);

	// Lay out all status components, in order
	Enumeration status = leftOfScrollBar.elements();
	while (status.hasMoreElements()) {
		Component comp = (Component) status.nextElement();
		Dimension dim = comp.getPreferredSize();
		comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight);
		ileft += dim.width;
	}

	bottom.setBounds(ileft, itop + centerHeight, size.width - rightWidth - ileft - iright, bottomHeight);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:30,代码来源:JEditTextArea.java

示例3: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Lays out the specified container.
 * @param parent the container to be laid out
 */
public void layoutContainer(Container parent) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension size = parent.getSize();
    int c = horizontal ? insets.left : insets.top;
    int x, y;
    int ebx = size.width - insets.right;
    size.width -= (insets.left + insets.right);
    size.height -= (insets.top + insets.bottom);
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        Dimension pref = comp.getPreferredSize();
        if (comp instanceof EnableButton) {
            ebx -= 4;
            ebx -= pref.width;
            x = ebx;
            y = (insets.top - pref.height) / 2;
        } else if (horizontal) {
            x = c;
            c += pref.width;
            y = insets.top;
            pref.height = size.height;
        } else {
            x = insets.left;
            pref.width = size.width;
            y = c;
            c += pref.height;
        }
        comp.setBounds(x, y, pref.width, pref.height);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:CompactLayout.java

示例4: layoutSize

import java.awt.Container; //导入方法依赖的package包/类
/**
 * 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;
		}

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

		//  Fit components into the allowed width

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

		final int nmembers = target.getComponentCount();

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

			if (m.isVisible()) {
				final 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.

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

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

		return dim;
	}
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:79,代码来源:WrapLayout.java

示例5: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Lays out the container.
 *
 * @param target
 *            the container to lay out.
 */
public void layoutContainer(Container target) {
	Insets insets = target.getInsets();
	int maxheight = target.getSize().height
			- (insets.top + insets.bottom + vgap * 2);
	int maxwidth = target.getSize().width
			- (insets.left + insets.right + hgap * 2);
	int numcomp = target.getComponentCount();
	int x = insets.left + hgap, y = 0;
	int colw = 0, start = 0;

	for (int i = 0; i < numcomp; i++) {
		Component m = target.getComponent(i);
		if (m.isVisible()) {
			Dimension d = m.getPreferredSize();
			// fit last component to remaining height
			if ((this.vfill) && (i == (numcomp - 1))) {
				d.height = Math.max((maxheight - y),
						m.getPreferredSize().height);
			}

			// fit component size to container width
			if (this.hfill) {
				m.setSize(maxwidth, d.height);
				d.width = maxwidth;
			} else {
				m.setSize(d.width, d.height);
			}

			if (y + d.height > maxheight) {
				placethem(target, x, insets.top + vgap, colw,
						maxheight - y, start, i);
				y = d.height;
				x += hgap + colw;
				colw = d.width;
				start = i;
			} else {
				if (y > 0)
					y += vgap;
				y += d.height;
				colw = Math.max(colw, d.width);
			}
		}
	}
	placethem(target, x, insets.top + vgap, colw, maxheight - y, start,
			numcomp);
}
 
开发者ID:Harlber,项目名称:Method_Trace_Tool,代码行数:53,代码来源:VerticalFlowLayout.java

示例6: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param target
 *            Description of Parameter
 */
@Override
public void layoutContainer(Container target){
	synchronized(target.getTreeLock()){
		Insets insets=target.getInsets();
		int maxheight=target.getHeight()-(insets.top+insets.bottom+_vgap*2);
		int nmembers=target.getComponentCount();
		int y=0;
		
		Dimension preferredSize=preferredLayoutSize(target);
		Dimension targetSize=target.getSize();
		
		switch(_valign){
		case TOP:
			y=insets.top;
			break;
		case CENTER:
			y=(targetSize.height-preferredSize.height)/2;
			break;
		case BOTTOM:
			y=targetSize.height-preferredSize.height-insets.bottom;
			break;
		}
		
		for(int i=0;i<nmembers;i++){
			Component m=target.getComponent(i);
			if(m.isVisible()){
				Dimension d=m.getPreferredSize();
				m.setSize(d.width, d.height);
				
				if(y+d.height<=maxheight){
					if(y>0){
						y+=_vgap;
					}
					
					int x=0;
					switch(_halign){
					case LEFT:
						x=insets.left;
						break;
					case CENTER:
						x=(targetSize.width-d.width)/2;
						break;
					case RIGHT:
						x=targetSize.width-d.width-insets.right;
						break;
					}
					
					m.setLocation(x, y);
					
					y+=d.getHeight();
					
				}else{
					break;
				}
			}
		}
	}
}
 
开发者ID:LapisSea,项目名称:OpenGL-Bullet-engine,代码行数:65,代码来源:VerticalFlowLayout.java

示例7: minimumLayoutSize

import java.awt.Container; //导入方法依赖的package包/类
@Override
public Dimension minimumLayoutSize(Container container) {
    return container.getSize();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:MultiSplitPane.java

示例8: preferredLayoutSize

import java.awt.Container; //导入方法依赖的package包/类
@Override
public Dimension preferredLayoutSize(Container container) {
    return container.getSize();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:MultiSplitPane.java

示例9: layoutSize

import java.awt.Container; //导入方法依赖的package包/类
/**
 * 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.

    Dimension targetSize = target.getSize();
    int targetWidth = 0;

    if (targetSize.width == 0)
      targetWidth = Integer.MAX_VALUE;
    else
      targetWidth = targetSize.width;

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

    //  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();

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

        if (rowWidth > 0) {
          rowWidth += getHgap();
        }

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

    addRow(dim, rowWidth, rowHeight);

    dim.width += insets.left + insets.right + hgap * 2;
    dim.height += insets.top + insets.bottom + vgap * 2;

    return dim;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:65,代码来源:WrapLayout.java

示例10: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Lays out the container using the FlowLayout. If the components as laid
 * out do not fit in the size of then cause tree to be layout again unless
 * this is a recursive call.
 */
@Override
public void layoutContainer(final Container target) {
  super.layoutContainer(target);

  /*
   * Now see how big a container is needed to hold all components
   */
  int maxX = 0;
  int maxY = 0;

  for (int i = 0; i < target.getComponentCount(); i++) {
    final Component cmp = target.getComponent(i);
    if (!cmp.isVisible()) {
      continue;
    }

    final Rectangle b = cmp.getBounds();

    if (b.x + b.width > maxX) {
      maxX = b.x + b.width;
    }

    if (b.y + b.height > maxY) {
      maxY = b.y + b.height;
    }
  }

  final Dimension size = target.getSize();

  if (maxX > size.width || maxY > size.height) {
    if (recursing) {
      return;
    }

    recursing = true;
    target.invalidate();

    if (target instanceof JComponent) {
      ((JComponent)target).revalidate();
    }

    recursing = false;
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:50,代码来源:WrapLayout.java

示例11: showComponent

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Show the hideable component
 */
public void showComponent() {
  if (getHideableComponent().isVisible()) {
    return;
  }

  if (resizeOnVisibilityChange) {
    final Container ancestor = getTopLevelAncestor();
    if (ancestor == null) {
      return;
    }

    final Rectangle screenBounds = Info.getScreenBounds(ancestor);
    final Point ancestorPos = ancestor.getLocation();
    final Dimension ancestorSize = ancestor.getSize();
    final Dimension prefHSize = getHideableComponent().getPreferredSize();
    final Dimension prefBSize = getBaseComponent().getPreferredSize();

    double div = 0.0;
    int w = 0, h = 0;
    switch (getOrientation()) {
    case JSplitPane.HORIZONTAL_SPLIT:
      w = Math.min(
        ancestorSize.width + prefHSize.width,
        screenBounds.width - ancestorPos.x
      );
      h = ancestorSize.height;
      div = prefBSize.width/(double)(prefBSize.width + prefHSize.width);
      break;
    case JSplitPane.VERTICAL_SPLIT:
      w = ancestorSize.width;
      h = Math.min(
        ancestorSize.height + prefHSize.height,
        screenBounds.height - ancestorPos.y
      );
      div = prefBSize.height/(double)(prefBSize.height + prefHSize.height);
      break;
    }

    ancestor.setSize(w, h);
    ancestor.validate();
    getHideableComponent().setVisible(true);
    ((BasicSplitPaneUI) getUI()).getDivider().setVisible(true);

    final double divPos = div;
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        setDividerLocation(divPos);
      }
    });
  }
  else {
    getHideableComponent().setVisible(true);
    ((BasicSplitPaneUI) getUI()).getDivider().setVisible(true);

    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        setDividerLocation(getPreferredDividerLocation());
      }
    });

    final SplitPane split = getTransverseSplit();
    if (split != null) {
      split.showTransverseComponent(ComponentSplitter.SplitPane.this);
    }
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:70,代码来源:ComponentSplitter.java

示例12: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container container)
{
	Insets insets = container.getInsets();
	int i = container.getSize().height - (insets.top + insets.bottom + vgap * 2);
	int j = container.getSize().width - (insets.left + insets.right + hgap * 2);
	int k = container.getComponentCount();
	int x = insets.left + hgap;
	int i1 = 0;
	int j1 = 0;
	int k1 = 0;
	for( int l1 = 0; l1 < k; l1++ )
	{
		Component component = container.getComponent(l1);
		if( component.isVisible() )
		{
			Dimension dimension = component.getPreferredSize();
			if( vfill && l1 == k - 1 )
			{
				dimension.height = Math.max(i - i1, component.getPreferredSize().height);
			}

			if( hfill )
			{
				component.setSize(j, dimension.height);
				dimension.width = j;
			}
			else
			{
				component.setSize(dimension.width, dimension.height);
			}

			if( i1 + dimension.height > i )
			{
				placethem(container, x, insets.top + vgap, i - i1, k1, l1);
				i1 = dimension.height;
				x += hgap + j1;
				j1 = dimension.width;
				k1 = l1;
			}
			else
			{
				if( i1 > 0 )
				{
					i1 += vgap;
				}
				i1 += dimension.height;
				j1 = Math.max(j1, dimension.width);
			}
		}
	}

	placethem(container, x, insets.top + vgap, i - i1, k1, k);
}
 
开发者ID:equella,项目名称:Equella,代码行数:55,代码来源:VerticalFlowLayout.java

示例13: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
/**
 * Description of the Method
 *
 * @param target Description of Parameter
 */
public void layoutContainer(Container target) {
    synchronized (target.getTreeLock()) {
        Insets insets = target.getInsets();
        int maxheight = target.getHeight() - (insets.top + insets.bottom);// + _vgap * 2);
        int nmembers = target.getComponentCount();
        int y = 0;

        Dimension preferredSize = preferredLayoutSize(target);
        Dimension targetSize = target.getSize();

        switch (_valign) {
            case TOP:
                y = insets.top;
                break;
            case CENTER:
                y = (targetSize.height - preferredSize.height) / 2;
                break;
            case BOTTOM:
                y = targetSize.height - preferredSize.height - insets.bottom;
                break;
        }

        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                m.setSize(d.width, d.height);

                if ((y + d.height) <= maxheight) {
                    if (y > 0) {
                        y += _vgap;
                    }

                    int x = 0;
                    switch (_halign) {
                        case LEFT:
                            x = insets.left;
                            break;
                        case CENTER:
                            x = (targetSize.width - d.width) / 2;
                            break;
                        case RIGHT:
                            x = targetSize.width - d.width - insets.right;
                            break;
                    }

                    m.setLocation(x, y);

                    y += d.getHeight();

                } else {
                    break;
                }
            }
        }
    }
}
 
开发者ID:TheCaveCz,项目名称:letsmake-ledmatrix,代码行数:63,代码来源:VerticalFlowLayout.java

示例14: layoutContainer

import java.awt.Container; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container parent) {
	Dimension pref = preferredLayoutSize(parent);
	int[] prefRow = this.prefRow;
	int[] prefCol = this.prefCol;
	Dimension size = parent.getSize();

	double y0;
	int yRemaining = size.height - pref.height;
	double rowWeightTotal = 0.0;
	if (yRemaining != 0 && rowWeight != null) {
		for (double weight : rowWeight) {
			rowWeightTotal += weight;
		}
	}
	if (rowWeightTotal == 0.0 && yRemaining > 0) {
		y0 = yRemaining / 2.0;
	} else {
		y0 = 0;
	}

	int x0 = (size.width - pref.width) / 2;
	if (x0 < 0)
		x0 = 0;
	double y = y0;
	int i = -1;
	for (Component[] row : contents) {
		i++;
		int yRound = (int) (y + 0.5);
		int x = x0;
		for (int j = 0; j < row.length; j++) {
			Component comp = row[j];
			if (comp != null) {
				row[j].setBounds(x, yRound, prefCol[j], prefRow[i]);
			}
			x += prefCol[j];
		}
		y += prefRow[i];
		if (rowWeightTotal > 0 && i < rowWeight.length) {
			y += yRemaining * rowWeight[i] / rowWeightTotal;
		}
	}

	// TODO Auto-generated method stub

}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:47,代码来源:TableLayout.java


注:本文中的java.awt.Container.getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。