List of usage examples for java.awt Container getHeight
public int getHeight()
From source file:Main.java
public static void setScreenCenter(Container container) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension screenDimension = toolkit.getScreenSize(); int width = container.getWidth(); int height = container.getHeight(); Point point = new Point(); point.setLocation((screenDimension.getWidth() - width) / 2, (screenDimension.getHeight() - height) / 2); container.setLocation(point);/*from w w w.j a v a2s .c o m*/ }
From source file:Main.java
public static void showOnSameScreenAsMouseCenter(Container frame) { Point mouseLocation = MouseInfo.getPointerInfo().getLocation(); GraphicsDevice device;//from w w w .ja v a2 s . co m GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice lstGDs[] = ge.getScreenDevices(); ArrayList<GraphicsDevice> lstDevices = new ArrayList<GraphicsDevice>(lstGDs.length); for (GraphicsDevice gd : lstGDs) { GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screenBounds = gc.getBounds(); if (screenBounds.contains(mouseLocation)) { lstDevices.add(gd); } } if (lstDevices.size() > 0) { device = lstDevices.get(0); } else { device = ge.getDefaultScreenDevice(); } Rectangle bounds = device.getDefaultConfiguration().getBounds(); frame.setLocation(bounds.x + bounds.width / 2 - frame.getWidth() / 2, bounds.y + bounds.height / 2 - frame.getHeight() / 2); }
From source file:WrapperLayout.java
public void layoutContainer(Container arg0) { int count = arg0.getComponentCount(); if (count > 0) { Component child = arg0.getComponent(0); java.awt.Insets insets = arg0.getInsets(); child.setBounds(insets.left, insets.top, arg0.getWidth() - insets.left - insets.right, arg0.getHeight() - insets.top - insets.bottom); }//w ww. ja v a2 s. c o m }
From source file:Main.java
public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int maxWidth = parent.getWidth() - (insets.left + insets.right); int maxHeight = parent.getHeight() - (insets.top + insets.bottom); int nComps = parent.getComponentCount(); int previousWidth = 0, previousHeight = 0; int x = 0, y = insets.top; int rowh = 0, start = 0; int xFudge = 0, yFudge = 0; boolean oneColumn = false; // Go through the components' sizes, if neither // preferredLayoutSize nor minimumLayoutSize has // been called. if (sizeUnknown) { setSizes(parent);//from w w w. j av a 2s . c o m } if (maxWidth <= minWidth) { oneColumn = true; } if (maxWidth != preferredWidth) { xFudge = (maxWidth - preferredWidth) / (nComps - 1); } if (maxHeight > preferredHeight) { yFudge = (maxHeight - preferredHeight) / (nComps - 1); } for (int i = 0; i < nComps; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { Dimension d = c.getPreferredSize(); // increase x and y, if appropriate if (i > 0) { if (!oneColumn) { x += previousWidth / 2 + xFudge; } y += previousHeight + vgap + yFudge; } // If x is too large, if ((!oneColumn) && (x + d.width) > (parent.getWidth() - insets.right)) { // reduce x to a reasonable number. x = parent.getWidth() - insets.bottom - d.width; } // If y is too large, if ((y + d.height) > (parent.getHeight() - insets.bottom)) { // do nothing. // Another choice would be to do what we do to x. } // Set the component's size and position. c.setBounds(x, y, d.width, d.height); previousWidth = d.width; previousHeight = d.height; } } }
From source file:CenterLayout.java
public void layoutContainer(Container container) { int count = container.getComponentCount(); if (count > 0) { Component child = container.getComponent(0); java.awt.Insets insets = container.getInsets(); int availWidth = container.getWidth() - insets.left - insets.right; int availHeight = container.getHeight() - insets.top - insets.bottom; Dimension preferredSize = child.getPreferredSize(); double preferredWidth = preferredSize.getWidth(); double preferredHeight = preferredSize.getHeight(); int width; int height; int x;//from w w w . jav a 2s . co m int y; if (preferredWidth < availWidth) { x = (int) Math.round(insets.left + (availWidth - preferredWidth) / 2); width = (int) Math.round(preferredWidth); } else { x = insets.left; width = availWidth; } if (preferredHeight < availHeight) { y = (int) Math.round(insets.top + (availHeight - preferredHeight) / 2); height = (int) Math.round(preferredHeight); } else { y = insets.top; height = availHeight; } child.setBounds(x, y, width, height); } }
From source file:VerticalFlowLayout.java
/** * Description of the Method/*w w w. j av a2 s . com*/ * *@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; } } } } }
From source file:StackLayout.java
public void layoutContainer(Container parent) { Component visibleComp = getVisibleComponent(); if (visibleComp != null) { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); visibleComp.setBounds(insets.left, insets.top, parent.getWidth() - (insets.left + insets.right), parent.getHeight() - (insets.top + insets.bottom)); }/* ww w . ja v a2 s . c om*/ } }
From source file:EdgeLayoutExample.java
public void layoutContainer(Container parent) { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); int top = insets.top; int left = insets.left; Dimension minimumSize = minimumLayoutSize(parent); int height = minimumSize.height; int width = minimumSize.width; int availableHeight = parent.getHeight() - insets.bottom - insets.top; int availableWidth = parent.getWidth() - insets.left - insets.right; if (height < availableHeight) { height = availableHeight;//from w w w . java 2 s . com } if (width < availableWidth) { width = availableWidth; } int bottom = availableHeight; int right = availableWidth; Dimension preferredSize = preferredLayoutSize(parent); int preferredWidthAvailable = width - preferredSize.width; int preferredHeightAvailable = height - preferredSize.height; Component centerComp = null; for (int i = 0; i < this.components.size(); i++) { Component c = (Component) this.components.get(i); String constraint = (String) this.constraints.get(c); if (constraint.equals(CENTER)) { centerComp = c; } else { int compHeight; int compWidth; int xOrigin; int yOrigin; if (constraint.equals(NORTH) || constraint.equals(SOUTH)) { compWidth = width; if (preferredHeightAvailable > 0) { int preferredHeightNeeded = c.getPreferredSize().height - c.getMinimumSize().height; if (preferredHeightAvailable > preferredHeightNeeded) { compHeight = c.getPreferredSize().height; preferredHeightAvailable -= preferredHeightNeeded; } else { compHeight = c.getMinimumSize().height + preferredHeightAvailable; preferredHeightAvailable = 0; } } else { compHeight = c.getMinimumSize().height; } height = height - compHeight; xOrigin = left; if (constraint.equals(NORTH)) { yOrigin = top; top += compHeight; } else { yOrigin = bottom - compHeight; bottom = yOrigin; } } else { compHeight = height; if (preferredWidthAvailable > 0) { int preferredWidthNeeded = c.getPreferredSize().width - c.getMinimumSize().width; if (preferredWidthAvailable > preferredWidthNeeded) { compWidth = c.getPreferredSize().width; preferredWidthAvailable -= preferredWidthNeeded; } else { compWidth = c.getMinimumSize().width + preferredWidthAvailable; preferredWidthAvailable = 0; } } else { compWidth = c.getMinimumSize().width; } width = width - compWidth; yOrigin = top; if (constraint.equals(WEST)) { xOrigin = left; left += compWidth; } else { xOrigin = right - compWidth; right = xOrigin; } } c.setSize(compWidth, compHeight); c.setBounds(xOrigin, yOrigin, compWidth, compHeight); } if (centerComp != null) { c.setSize(width, height); c.setBounds(left, top, width, height); } } } }
From source file:StackLayout.java
private void layoutComponents(Container parent) { Component[] components = parent.getComponents(); Insets in = parent.getInsets(); int maxHeight = parent.getHeight() - in.top - in.bottom; int maxWidth = parent.getWidth() - in.left - in.right; boolean horiz = (ourOrientation == HORIZONTAL); int totalDepth = calculatePreferredDepth(components, ourOrientation); totalDepth = Math.max(totalDepth, (horiz ? maxHeight : maxWidth)); int prefLength = (ourLengthsMatched ? calculateAdjustedLength(components, ourOrientation, ourSpacing) : calculatePreferredLength(components, ourOrientation, ourSpacing)); int totalLength = Math.min(prefLength, (horiz ? maxWidth : maxHeight)); int a = (horiz ? in.left : in.top); int b = (horiz ? in.top : in.left); int l = 0, d = 0, sum = 0; int matchedLength = 0; Dimension prefsize = null;//from www . jav a 2s . co m if (ourLengthsMatched) { matchedLength = (horiz ? getMaxPrefWidth(components) : getMaxPrefHeight(components)); if (prefLength > totalLength && ourSqueezeFactor < 100) { int minLength = calculateMinimumLength(components, ourOrientation, ourSpacing); if (minLength >= totalLength) { matchedLength = (matchedLength * ourSqueezeFactor) / 100; } else { int numSeparators = countSeparators(components); int numComponents = components.length - numSeparators; int diff = (prefLength - totalLength) / numComponents; if ((prefLength - totalLength) % numComponents > 0) diff++; matchedLength -= diff; } } } for (int i = 0; i < components.length; i++) { prefsize = components[i].getPreferredSize(); if (!ourLengthsMatched) l = (horiz ? prefsize.width : prefsize.height); else l = matchedLength; if (components[i] instanceof JSeparator) { // l = Math.min(prefsize.width, prefsize.height); l = (horiz ? prefsize.width : prefsize.height); d = totalDepth; sum += l; if (ourDrop && sum > totalLength) l = 0; } else { sum += l; if (ourDrop && sum > totalLength) l = 0; else if (ourFill && !ourLengthsMatched && i == components.length - 1) { l = Math.max(l, (horiz ? maxWidth : maxHeight)); } if (ourDepthsMatched) d = totalDepth; else d = (horiz ? prefsize.height : prefsize.width); } if (horiz) components[i].setBounds(a, b + (totalDepth - d) / 2, l, d); else components[i].setBounds(b + (totalDepth - d) / 2, a, d, l); a += l + ourSpacing; sum += ourSpacing; } }
From source file:fxts.stations.ui.SideLayout.java
/** * Lays out the grid./*from ww w . j a v a2s . c o m*/ * * @param aParent the layout container */ protected void arrangeGrid(Container aParent) { ///////////////////////////////////////////////////////// //It`s only for debugging JComponent jc = (JComponent) aParent; String sType = (String) jc.getClientProperty("TYPE"); if (sType != null) { boolean bInternal = "internal".equals(sType); mLogger.debug("\n" + sType); } ////////////////////////////////////////////////////////// Component comp; int compindex; SideConstraints constraints; Insets insets = aParent.getInsets(); Component[] components = aParent.getComponents(); Dimension d; Rectangle r = new Rectangle(); int i, diffw, diffh; double weight; SideLayoutInfo info; mRightToLeft = !aParent.getComponentOrientation().isLeftToRight(); /* * If the parent has no slaves anymore, then don't do anything * at all: just leave the parent's size as-is. */ if (components.length == 0 && (mColumnWidths == null || mColumnWidths.length == 0) && (mRowHeights == null || mRowHeights.length == 0)) { return; } /* * Pass #1: scan all the slaves to figure out the total amount * of space needed. */ info = getLayoutInfo(aParent, PREFERREDSIZE); d = getMinSize(aParent, info); // // System.out.println("parent=w:" + parent.getWidth() + ",h:" + parent.getHeight() + // "min=w:" + d.getWidth() + ",h:" + d.getHeight()); if (aParent.getWidth() < d.width || aParent.getHeight() < d.height) { info = getLayoutInfo(aParent, MINSIZE); d = getMinSize(aParent, info); // // System.out.println("MINSIZE"); } else { // // System.out.println("Non MINSIZE"); } mLayoutInfo = info; r.width = d.width; r.height = d.height; /* * If the current dimensions of the window don't match the desired * dimensions, then adjust the minWidth and minHeight arrays * according to the weights. */ diffw = aParent.getWidth() - r.width; // // System.out.println("diffw=" + diffw); if (diffw != 0) { weight = 0.0; for (i = 0; i < info.width; i++) { weight += info.weightX[i]; } if (weight > 0.0) { for (i = 0; i < info.width; i++) { int dx = (int) (((double) diffw * info.weightX[i]) / weight); info.minWidth[i] += dx; r.width += dx; if (info.minWidth[i] < 0) { r.width -= info.minWidth[i]; info.minWidth[i] = 0; } } } diffw = aParent.getWidth() - r.width; } else { diffw = 0; } diffh = aParent.getHeight() - r.height; // // System.out.println("diffh=" + diffh); if (diffh != 0) { weight = 0.0; for (i = 0; i < info.height; i++) { weight += info.weightY[i]; } if (weight > 0.0) { for (i = 0; i < info.height; i++) { int dy = (int) (((double) diffh * info.weightY[i]) / weight); info.minHeight[i] += dy; r.height += dy; if (info.minHeight[i] < 0) { r.height -= info.minHeight[i]; info.minHeight[i] = 0; } } } diffh = aParent.getHeight() - r.height; } else { diffh = 0; } /* * Now do the actual layout of the slaves using the layout information * that has been collected. */ info.startx = /*diffw/2 +*/ insets.left; info.starty = /*diffh/2 +*/ insets.top; // // System.out.println("info.startx = " + info.startx); // System.out.println("info.starty = " + info.startx); for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) { continue; } constraints = lookupConstraints(comp); if (!mRightToLeft) { r.x = info.startx; for (i = 0; i < constraints.tempX; i++) { r.x += info.minWidth[i]; } } else { r.x = aParent.getWidth() - insets.right; for (i = 0; i < constraints.tempX; i++) { r.x -= info.minWidth[i]; } } r.y = info.starty; for (i = 0; i < constraints.tempY; i++) { r.y += info.minHeight[i]; } r.width = 0; for (i = constraints.tempX; i < constraints.tempX + constraints.tempWidth; i++) { r.width += info.minWidth[i]; } r.height = 0; for (i = constraints.tempY; i < constraints.tempY + constraints.tempHeight; i++) { r.height += info.minHeight[i]; } adjustForGravity(constraints, r); if (r.x < 0) { r.width -= r.x; r.x = 0; } if (r.y < 0) { r.height -= r.y; r.y = 0; } /* * If the window is too small to be interesting then * unmap it. Otherwise configure it and then make sure * it's mapped. */ if (r.width <= 0 || r.height <= 0) { comp.setBounds(0, 0, 0, 0); } else { if (comp.getX() != r.x || comp.getY() != r.y || comp.getWidth() != r.width || comp.getHeight() != r.height) { comp.setBounds(r.x, r.y, r.width, r.height); } } // System.out.println("Initial component size (x = " + (int)comp.getX() + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight())); if (diffw > 0) { // System.out.println("It`s increasing by x!"); //if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); //IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds((int) (comp.getX() + diffw * param.getLeft()), comp.getY(), (int) (comp.getWidth() + diffw * (param.getRight() - param.getLeft())), comp.getHeight()); // System.out.println("Set Bounds (x = " + (int)(comp.getX() + diffw * param.getLeft()) + // ", y = " + (int)(comp.getY()) + // ", widht = " + (int)(comp.getWidth() + /// diffw * (param.getRight() - param.getLeft())) + // ", height = " + (int)(comp.getHeight())); // } } if (diffh > 0) { // System.out.println("It`s increasing by y!"); // if (comp instanceof IResizableComponent) { // System.out.println("It`s resizable component: " + comp); // IResizableComponent resizeComp = (IResizableComponent)comp; ResizeParameter param = constraints.resize; // System.out.println("Params: Left=" + param.getLeft() + ",top=" + param.getTop() + // ",Right=" + param.getRight() + ",bottom=" + param.getBottom()); comp.setBounds(comp.getX(), (int) (comp.getY() + diffh * param.getTop()), comp.getWidth(), (int) (comp.getHeight() + diffh * (param.getBottom() - param.getTop()))); // System.out.println("Set Bounds (x = " + (int)(comp.getX()) + // ", y = " + (int)(comp.getY() + diffh * param.getTop()) + // ", widht = " + (int)(comp.getWidth()) + // ", height = " + (int)(comp.getHeight() + // diffh * (param.getBottom() - param.getTop()))); // } } } }