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


Java Component.getPreferredSize方法代码示例

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


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

示例1: minimumLayoutSize

import java.awt.Component; //导入方法依赖的package包/类
public Dimension minimumLayoutSize(final Container parent) {
    final Insets insets = parent.getInsets();
    final Dimension d = new Dimension(insets.left + insets.right,
                                      insets.top + insets.bottom);
    int maxWidth = 0;
    int visibleCount = 0;

    for (Component comp : parent.getComponents()) {
        if (comp.isVisible() && !(comp instanceof Box.Filler)) {
            final Dimension size = comp.getPreferredSize();
            maxWidth = Math.max(maxWidth, size.width);
            d.height += size.height;
            visibleCount++;
        }
    }

    d.height += (visibleCount - 1) * vGap;
    d.width += maxWidth;

    return d;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:VerticalLayout.java

示例2: updateSplitLocation

import java.awt.Component; //导入方法依赖的package包/类
/**
 * TODO: to remove? doesn't seems to be used anywhere.
 */
protected void updateSplitLocation(JSplitPane split, int foo) {
  Component left = split.getLeftComponent();
  Component right = split.getRightComponent();
  if(left == null) {
    split.setDividerLocation(0);
    return;
  }
  if(right == null) {
    split.setDividerLocation(1);
    return;
  }
  Dimension leftPS = left.getPreferredSize();
  Dimension rightPS = right.getPreferredSize();
  double location =
      split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT
          ? (double)leftPS.width / (leftPS.width + rightPS.width)
          : (double)leftPS.height / (leftPS.height + rightPS.height);
  split.setDividerLocation(location);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:23,代码来源:DocumentEditor.java

示例3: preferredLayoutSize

import java.awt.Component; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public Dimension preferredLayoutSize(Container parent) {
    int width = 0;
    int height = 0;
    for (Component comp : parent.getComponents()) {
        Dimension size = comp.getPreferredSize();
        if (size != null) {
            width = Math.max(width, size.width);
            height = Math.max(height, size.height);
        }
    }
    componentDimension = new Dimension(width, height);
    int w = MAX_COLUMNS * (width + gap) + gap;
    int h = MAX_ROWS * (height + gap) + gap;
    Dimension dimension = new Dimension(w, h);
    return dimension;
}
 
开发者ID:fgulan,项目名称:java-course,代码行数:20,代码来源:CalcLayout.java

示例4: layoutContainer

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    int x = insets.left;
    int y = insets.top;
    int columnWidth = 0;
    int limitHeight = parent.getHeight() - insets.bottom;
    for (Component c : this.components) {
        if (c.isVisible()) {
            Dimension d = c.getPreferredSize();
            columnWidth = Math.max(columnWidth, d.width);
            if (y + d.height >= limitHeight) {
                x += columnWidth + this.hgap;
                y = insets.top;
            }
            c.setBounds(x, y, d.width, d.height);
            y += d.height + this.vgap;
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:VerticalFlowLayout.java

示例5: evalSize

import java.awt.Component; //导入方法依赖的package包/类
private Dimension evalSize(Container parent, boolean min) {
	synchronized (parent.getTreeLock()) {
		int w = 0, h = 0;
		int nrows = 1, ncols = 1;
		int row = 0, col = 0;
		// eval max size and rows/cols
		for (Component cmp : parent.getComponents())
			if (cmp.isVisible()) {
				ncols = col + 1;
				if (row >= nrows)
					nrows = row + 1;
				// eval size
				Dimension d = min ? cmp.getMinimumSize() : cmp
						.getPreferredSize();
				if (w < d.width)
					w = d.width;
				if (h < d.height)
					h = d.height;
				// eval matrix
				if (++row >= getRows()) {
					row = 0;
					col++;
				}
			}
		// add insets
		Insets insets = parent.getInsets();
		return new Dimension(insets.left + insets.right + ncols * w
				+ (ncols - 1) * getHgap(), insets.top + insets.bottom
				+ nrows * h + (nrows - 1) * getVgap());
	}
}
 
开发者ID:KeepTheBeats,项目名称:alevin-svn2,代码行数:32,代码来源:MyGridLayout.java

示例6: autoSizeTableColumns

import java.awt.Component; //导入方法依赖的package包/类
public static void autoSizeTableColumns(JTable table) {

        TableModel  model        = table.getModel();
        TableColumn column       = null;
        Component   comp         = null;
        int         headerWidth  = 0;
        int         maxCellWidth = Integer.MIN_VALUE;
        int         cellWidth    = 0;
        TableCellRenderer headerRenderer =
            table.getTableHeader().getDefaultRenderer();

        for (int i = 0; i < table.getColumnCount(); i++) {
            column = table.getColumnModel().getColumn(i);
            comp = headerRenderer.getTableCellRendererComponent(table,
                    column.getHeaderValue(), false, false, 0, 0);
            headerWidth  = comp.getPreferredSize().width + 10;
            maxCellWidth = Integer.MIN_VALUE;

            for (int j = 0; j < Math.min(model.getRowCount(), 30); j++) {
                TableCellRenderer r = table.getCellRenderer(j, i);

                comp = r.getTableCellRendererComponent(table,
                                                       model.getValueAt(j, i),
                                                       false, false, j, i);
                cellWidth = comp.getPreferredSize().width;

                if (cellWidth >= maxCellWidth) {
                    maxCellWidth = cellWidth;
                }
            }

            column.setPreferredWidth(Math.max(headerWidth, maxCellWidth)
                                     + 10);
        }
    }
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:36,代码来源:GridSwing.java

示例7: preferredLayoutSize

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Returns the preferred dimensions for this layout given the components
 * in the specified target container.
 * @param parent the component which needs to be laid out
 * @return a <code>Dimension</code> object containing the
 *          preferred dimensions
 * @see #minimumLayoutSize
 */
public Dimension preferredLayoutSize(Container parent) {
    Component view = ((JViewport)parent).getView();
    if (view == null) {
        return new Dimension(0, 0);
    }
    else if (view instanceof Scrollable) {
        return ((Scrollable)view).getPreferredScrollableViewportSize();
    }
    else {
        return view.getPreferredSize();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ViewportLayout.java

示例8: MaximizedCellRenderer

import java.awt.Component; //导入方法依赖的package包/类
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:XMBeanAttributes.java

示例9: getHeaderHeight

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Calculate and return the height of the header.
 *
 * @return Header Height
 */
@SuppressWarnings("unchecked")
private int getHeaderHeight() {
    int height = 0;
    GroupableTableColumnModel columnModel = (GroupableTableColumnModel) header
            .getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = header.getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(header
                        .getTable(), aColumn.getHeaderValue(), false, false, -1,
                column);
        int cHeight = comp.getPreferredSize().height;
        Iterator iter = columnModel.getColumnGroups(aColumn);
        if (iter != null) {
            while (iter.hasNext()) {
                ColumnGroup cGroup = (ColumnGroup) iter.next();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    return height;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:32,代码来源:GroupableTableHeaderUI.java

示例10: layoutContainer

import java.awt.Component; //导入方法依赖的package包/类
@Override
public void layoutContainer(Container parent) {
    StyledDocument doc = (StyledDocument)editor.getDocument();
    for (Component comp : parent.getComponents()) {
        Position pos = positions.get(comp);
        int line = findLineNumber(doc, pos.getOffset());
        Dimension prefSize = comp.getPreferredSize();
        int dy = lineHeight() - prefSize.height;
        dy = dy > 0 ? dy / 2 + 1 : 0;
        comp.setBounds(LEFT_GAP,
                       line * lineHeight() + dy,
                       parent.getWidth() - LEFT_GAP - RIGHT_GAP,
                       Math.min(prefSize.height, lineHeight()));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CustomCodeView.java

示例11: sizeColumns

import java.awt.Component; //导入方法依赖的package包/类
private void sizeColumns() {
	/* try and resize columns according to their header and (if available) prototype width*/
	/* taken from Sun's JTable tutorial, with some added features */
	int colnum = dataModel.getColumnCount();
	TableColumn col;
	Component comp;
	PrototypedTableModel ptm = null;
	boolean hasPrototypes = false;
	int autoWidth;

	if (dataModel instanceof PrototypedTableModel) {
		hasPrototypes = true;
		ptm = (PrototypedTableModel) dataModel;
	}

	if (tableHeader == null) {
		return; // hack: skip column sizing until we actually have a header
	}

	for (int i = 0; i < colnum; i++) {
		col = columnModel.getColumn(i);

		comp = tableHeader.getDefaultRenderer().getTableCellRendererComponent(null, col.getHeaderValue(), false, false, 0, i);
		autoWidth = comp.getPreferredSize().width;

		if (hasPrototypes) {
			//comp = getDefaultRenderer(dataModel.getColumnClass(i)).getTableCellRendererComponent(this, ptm.getPrototype(i), false, false, 0, i);
			comp = getDefaultRenderer(Object.class).getTableCellRendererComponent(this, ptm.getPrototype(i), false, false, 0, i);
			autoWidth = Math.max(autoWidth, comp.getPreferredSize().width);
		}

		col.setPreferredWidth(autoWidth);
	}
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:35,代码来源:ExactTable.java

示例12: getMenuItemsHeight

import java.awt.Component; //导入方法依赖的package包/类
private int getMenuItemsHeight() {
    int height = 0;
    for (Component c : this.components) {
        height += c.getPreferredSize().height;
    }
    return height;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:VerticalGridLayout.java

示例13: initColumnSizes

import java.awt.Component; //导入方法依赖的package包/类
/**
 * This method picks good column sizes. If all column headers are wider than
 * the column's cells' contents, then just use column.sizeWidthToFit().
    * @param table  JTable
    */
public void initColumnSizes(JTable table) {

	TableColumn column;
	Component comp;
	int headerWidth;
	int cellWidth;

	TableCellRenderer headerRenderer = table.getTableHeader()
			.getDefaultRenderer();

	// TODO: move to tableModel. AK
	for (int i = 0; i < this.variationPerParameterTableModel.getColumnCount(); i++) {
		column = table.getColumnModel().getColumn(i);

		comp = headerRenderer.getTableCellRendererComponent(null, column
				.getHeaderValue(), false, false, 0, 0);
		headerWidth = comp.getPreferredSize().width;

		// /TODO: move to tableModel. AK
		comp = table.getDefaultRenderer(this.variationPerParameterTableModel.getColumnClass(i))
				.getTableCellRendererComponent(table, this.variationPerParameterTableModel.longValues[i], false,
						false, 0, i);
		cellWidth = comp.getPreferredSize().width;

		// XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
		column.setPreferredWidth(Math.max(headerWidth, cellWidth));
	}
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:34,代码来源:VariationPerParameterTableController.java

示例14: getRowWidths

import java.awt.Component; //导入方法依赖的package包/类
private int[] getRowWidths() 
{
	int[] rowWidths = new int[componentListByRow.size()]; 
	
	for(int row = 0; row < componentListByRow.size(); ++row )
	{
		List<Component> components = componentListByRow.get(row); 
		for( Component comp : components )
		{
			if( !comp.isVisible() )continue;
			rowWidths[row] += comp.getPreferredSize().width;
		}
	}
	return rowWidths;
}
 
开发者ID:jpxor,项目名称:slick,代码行数:16,代码来源:SlickLayout.java

示例15: layoutContainer

import java.awt.Component; //导入方法依赖的package包/类
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:MetalworksPrefs.java


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