本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例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());
}
}
示例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);
}
}
示例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();
}
}
示例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));
}
}
示例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;
}
示例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()));
}
}
示例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);
}
}
示例12: getMenuItemsHeight
import java.awt.Component; //导入方法依赖的package包/类
private int getMenuItemsHeight() {
int height = 0;
for (Component c : this.components) {
height += c.getPreferredSize().height;
}
return height;
}
示例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));
}
}
示例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;
}
示例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;
}
}