Java Code Examples for java.awt.Container#getBounds()

The following examples show how to use java.awt.Container#getBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DelegateViewport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void scrollRectToVisible(Rectangle contentRect) {
    Container parent;
    int dx = getX(), dy = getY();

    for (parent = getParent();
             !(parent == null) &&
             !(parent instanceof JComponent) &&
             !(parent instanceof CellRendererPane);
         parent = parent.getParent()) {
         Rectangle bounds = parent.getBounds();

         dx += bounds.x;
         dy += bounds.y;
    }

    if (!(parent == null) && !(parent instanceof CellRendererPane)) {
        contentRect.x += dx;
        contentRect.y += dy;

        ((JComponent) parent).scrollRectToVisible(contentRect);
        contentRect.x -= dx;
        contentRect.y -= dy;
    }
    
}
 
Example 2
Source File: CefClient.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Rectangle getViewRect(CefBrowser browser) {
   if (browser == null)
		return new Rectangle(0, 0, 0, 0);

	CefRenderHandler realHandler = browser.getRenderHandler();
   if (realHandler != null)
		return realHandler.getViewRect(browser);
   
	Rectangle tmp = browser.getUIComponent().getBounds();
	if (OS.isMacintosh()) {
		Container parent = browser.getUIComponent().getParent();
		while (parent != null) {
			Container next = parent.getParent();
            if (next != null && next instanceof Window)
					break;

			Rectangle parentRect = parent.getBounds();
			tmp.x += parentRect.x;
			tmp.y += parentRect.y;
			parent = next;
		}
	}
	return tmp;
}
 
Example 3
Source File: ViewElement.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void focusGained(FocusEvent e) {
	Component c = e.getComponent();

	// I need the absolute position of this component in the top-most component inside the JScrollPane
	// in order to call scrollRectToVisible() with the correct coordinates.
	Rectangle rec = c.getBounds();
	//Log.message("START "+c.getClass().getName() + " >> "+rec.y);
	
	Container c0 = null;
	Container c1 = c.getParent();
	while( (c1!=null) && !(c1 instanceof JScrollPane) ) {
		Rectangle r2 = c1.getBounds();
		rec.x += r2.x;
		rec.y += r2.y;
		//Log.message("\t"+c1.getClass().getName() + " REL "+r2.y+" ABS "+rec.y);
		c0 = c1;
		c1 = c1.getParent();
	}
	//Log.message("\tFINAL "+c0.getClass().getName() + " >> "+rec.y);
	
	((JComponent)c0).scrollRectToVisible(rec);
}
 
Example 4
Source File: TableExample.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 5
Source File: TableExample.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 6
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Forwards the {@code scrollRectToVisible()} message to the
 * {@code JComponent}'s parent. Components that can service
 * the request, such as {@code JViewport},
 * override this method and perform the scrolling.
 *
 * @param aRect the visible {@code Rectangle}
 * @see javax.swing.JViewport
 */
@Override
public void scrollRectToVisible(Rectangle aRect)
{
	Container parent;
	int dx = getX();
	int dy = getY();

	for (parent = getParent(); (parent != null) && !(parent instanceof JComponent)
		&& !(parent instanceof CellRendererPane); parent = parent.getParent())
	{
		final Rectangle bounds = parent.getBounds();

		dx += bounds.x;
		dy += bounds.y;
	}

	if ((parent != null) && !(parent instanceof CellRendererPane))
	{
		aRect.x += dx;
		aRect.y += dy;

		((JComponent) parent).scrollRectToVisible(aRect);
		aRect.x -= dx;
		aRect.y -= dy;
	}
}
 
Example 7
Source File: OOODesktopManager.java    From noa-libre with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deiconifyFrame(JInternalFrame f) {
  JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
  Container c = desktopIcon.getParent();
  if (c != null) {
    f.setBounds(oldBounds.remove(f)); //XXX
    //c.add(f); //XXX

    // If the frame is to be restored to a maximized state make
    // sure it still fills the whole desktop.
    if (f.isMaximum()) {
      Rectangle desktopBounds = c.getBounds();
      if (f.getWidth() != desktopBounds.width || f.getHeight() != desktopBounds.height) {
        setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
      }
    }
    removeIconFor(f);
    if (f.isSelected()) {
      f.moveToFront();
    }
    else {
      try {
        f.setSelected(true);
      }
      catch (PropertyVetoException e2) {
      }
    }
  }
}
 
Example 8
Source File: Connector.java    From wandora with GNU General Public License v3.0 5 votes vote down vote up
protected Point getRootCoordinates(JComponent c,int x,int y){
    Container co=c;
    Point d=new Point(x,y);
    while(co!=null && co!=root){
        Rectangle rect=co.getBounds();
        d.setLocation(d.getX()+rect.x, d.getY()+rect.y);
        co=co.getParent();
    }
    return d;
}
 
Example 9
Source File: TableExample.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 10
Source File: JTreeTable.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Forwards the {@code scrollRectToVisible()} message to the
 * {@code JComponent}'s parent. Components that can service
 * the request, such as {@code JViewport},
 * override this method and perform the scrolling.
 *
 * @param aRect the visible {@code Rectangle}
 * @see javax.swing.JViewport
 */
@Override
public void scrollRectToVisible(Rectangle aRect)
{
	Container parent;
	int dx = getX();
	int dy = getY();

	for (parent = getParent(); (parent != null) && !(parent instanceof JComponent)
		&& !(parent instanceof CellRendererPane); parent = parent.getParent())
	{
		final Rectangle bounds = parent.getBounds();

		dx += bounds.x;
		dy += bounds.y;
	}

	if ((parent != null) && !(parent instanceof CellRendererPane))
	{
		aRect.x += dx;
		aRect.y += dy;

		((JComponent) parent).scrollRectToVisible(aRect);
		aRect.x -= dx;
		aRect.y -= dy;
	}
}
 
Example 11
Source File: TableExample.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 12
Source File: FlexLayout.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void layoutContainer(Container target) {
    if (mRootCell != null) {
        Rectangle bounds = target.getBounds();
        Insets    insets = target.getInsets();
        bounds.x = insets.left;
        bounds.y = insets.top;
        bounds.width -= insets.left + insets.right;
        bounds.height -= insets.top + insets.bottom;
        mRootCell.layout(Scale.get(target), bounds);
    }
}
 
Example 13
Source File: VerticalLayout.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Lays out the container in the specified panel.
 *
 * @param parent the component which needs to be laid out
 */
public void layoutContainer(final Container parent) {
    synchronized (parent.getTreeLock()) {
        final Insets ins = parent.getInsets();
        final int insHorizontal = ins.left + ins.right;

        final int width;
        if (isUseSizeFromParent()) {
            final Rectangle bounds = parent.getBounds();
            width = bounds.width - insHorizontal;
        }
        else {
            width = preferredLayoutSize(parent).width - insHorizontal;
        }
        final Component[] comps = parent.getComponents();

        int y = ins.top;
        for (int i = 0; i < comps.length; i++) {
            final Component c = comps[i];
            if (c.isVisible() == false) {
                continue;
            }
            final Dimension dim = c.getPreferredSize();
            c.setBounds(ins.left, y, width, dim.height);
            y += dim.height;
        }
    }
}
 
Example 14
Source File: TableExample.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 15
Source File: TableExample.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 16
Source File: TableExample.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 17
Source File: TableExample.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 18
Source File: FixedCenterLayout.java    From tn5250j with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lays out the target argument using this layout.
 */
public void layoutContainer(Container target) {
    synchronized (target.getTreeLock()) {
        Insets insets = target.getInsets();
        int top = insets.top;
        //	int bottom = target.getHeight() - insets.bottom;
        int bottom = target.getBounds().height - insets.bottom;
        int left = insets.left;
        //	int right = target.getWidth() - insets.right;
        int right = target.getBounds().width - insets.right;

        int leftCenter = (right-left)/2;
        int rightCenter = leftCenter;

        if (center != null) {
            Dimension d = center.getPreferredSize();
            leftCenter = (right-left-d.width)/2;
            rightCenter = leftCenter+d.width;
            center.setBounds(leftCenter, top, d.width, bottom-top);
        }
        if (west != null) {
            west.setBounds(left, top, leftCenter-left-hgap, bottom-top);
        }
        if (east != null) {
            east.setBounds(rightCenter+hgap, top, right-rightCenter-2*hgap, bottom-top);
        }
    }
}
 
Example 19
Source File: TableExample.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Rectangle b = c.getBounds();
    int topHeight = 90;
    int inset = 4;
    showConnectionInfoButton.setBounds(b.width - 2 * inset - 120, inset, 120,
            25);
    fetchButton.setBounds(b.width - 2 * inset - 120, 60, 120, 25);
    // queryLabel.setBounds(10, 10, 100, 25);
    queryAggregate.setBounds(inset, inset, b.width - 2 * inset - 150, 80);
    tableAggregate.setBounds(new Rectangle(inset,
            inset + topHeight,
            b.width - 2 * inset,
            b.height - 2 * inset - topHeight));
}
 
Example 20
Source File: LuckInternalFrameTitlePane.java    From littleluck with Apache License 2.0 2 votes vote down vote up
public void layoutContainer(Container c)
{
    boolean leftToRight = frame.getComponentOrientation().isLeftToRight();

    int w = getWidth();

    Rectangle bound = c.getBounds();

    int startX = (leftToRight) ? 4 : w - 16 - 5;

    menuBar.setBounds(startX, 4, 16, 16);

    // 起始x坐标
    startX = leftToRight ? bound.width : 0;

    if (frame.isClosable() && closeButton.getIcon() != null)
    {
        int closeBtnW = closeButton.getIcon().getIconWidth();

        int closeBtnH = closeButton.getIcon().getIconHeight();

        startX = leftToRight ? (startX - closeBtnW) : startX;

        closeButton.setBounds(startX, 0, closeBtnW, closeBtnH);

        startX = leftToRight ? startX : startX + closeBtnW;
    }

    if (frame.isMaximizable() && maxButton.getIcon() != null)
    {
        int maximizeBtnW = maxButton.getIcon().getIconWidth();

        int maximizeBtnH = maxButton.getIcon().getIconHeight();

        startX = leftToRight ? (startX - maximizeBtnW) : startX;

        maxButton.setBounds(startX, 0, maximizeBtnW, maximizeBtnH);

        startX = leftToRight ? startX : startX + maximizeBtnW;
    }

    if (frame.isIconifiable() && iconButton.getIcon() != null)
    {
        int minBtnW = iconButton.getIcon().getIconWidth();

        int minBtnH = iconButton.getIcon().getIconHeight();

        startX = leftToRight ? (startX - minBtnW) : startX;

        iconButton.setBounds(startX, 0, minBtnW, minBtnH);
    }
}