Example usage for java.awt Component setLocation

List of usage examples for java.awt Component setLocation

Introduction

In this page you can find the example usage for java.awt Component setLocation.

Prototype

public void setLocation(int x, int y) 

Source Link

Document

Moves this component to a new location.

Usage

From source file:pcgen.gui2.tools.Utility.java

/**
 * Centers a {@code JFrame} to the screen.
 *
 * @param frame   JFrame frame to center
 * @param isPopup boolean is the frame a popup dialog?
 *///  w ww  . j a  va  2s. c  om
public static void centerComponent(Component frame, boolean isPopup) {
    // since the Toolkit.getScreenSize() method is broken in the Linux implementation
    // of Java 5  (it returns double the screen size under xinerama), this method is
    // encapsulated to accomodate this with a hack.
    // TODO: remove the hack, once Java fixed this.
    // final Dimension screenSize = getScreenSize(Toolkit.getDefaultToolkit());
    final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().getBounds();

    if (isPopup) {
        frame.setSize(screenSize.width / 2, screenSize.height / 2);
    }

    final Dimension frameSize = frame.getSize();

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    frame.setLocation(screenSize.x + ((screenSize.width - frameSize.width) / 2),
            screenSize.y + ((screenSize.height - frameSize.height) / 2));
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static void centerComponentToContainer(Component component, Component container) {
    if (container.isDisplayable() == false) {
        container.addNotify();/*  w w  w.ja v a 2 s  .  co  m*/
    }
    component.setLocation((container.getWidth() - component.getWidth()) / 2,
            (container.getHeight() - component.getHeight()) / 2);
}

From source file:org.objectstyle.cayenne.modeler.pref.ComponentGeometry.java

void updateLocation(Component c, int maxOffset) {
    if (maxOffset != 0) {
        int xOffset = (int) (Math.random() * maxOffset);
        int yOffset = (int) (Math.random() * maxOffset);
        changeX(xOffset);/*from  ww  w. ja  va 2  s.  c  om*/
        changeY(yOffset);
    }

    int x = getIntX(-1);
    int y = getIntY(-1);

    if (x > 0 && y > 0) {
        c.setLocation(x, y);
    }
}

From source file:client.InterfaceJeu.java

public void selectionnerCarte(Component carte) {
    cartesSelectionnees.add(carte);/* w  ww  .  j av  a2 s .c om*/
    carte.setLocation(carte.getLocation().x, carte.getLocation().y - 10);
    verifierCartes();
}

From source file:client.InterfaceJeu.java

public void deselectionnerCarte(Component carte) {
    cartesSelectionnees.remove(carte);//  w w w  .  j  av  a 2  s .  c om
    carte.setLocation(carte.getLocation().x, carte.getLocation().y + 10);
    verifierCartes();
}

From source file:op.tools.SYSTools.java

public static void centerOnParent(Component parent, Component child) {

    Dimension dimParent = parent.getSize();
    Dimension dimChild = child.getSize();

    //Dimension them = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int newX = (dimParent.width - dimChild.width) / 2;
    int newY = (dimParent.height - dimChild.height) / 2;
    newX += parent.getX();// w  ww  .  java2 s .co m
    newY += parent.getY();
    child.setLocation(newX, newY);
}

From source file:org.kchine.rpf.PoolUtils.java

public static void locateInScreenCenter(Component c) {
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    c.setLocation((screenDim.width - c.getWidth()) / 2, (screenDim.height - c.getHeight()) / 2);
}

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method//from w  ww  .j a  v  a2  s  . co  m
 *
 *@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:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Sets the location of the passed component relative to the specified 
 * bounds./*  w  ww.jav a2s .c om*/
 * 
 * @param bounds    The bounds of the main component.
 * @param child     The location of the child
 */
public static void incrementRelativeToAndShow(Rectangle bounds, Component child) {
    if (bounds == null) {
        UIUtilities.centerAndShow(child);
        return;
    }
    child.setLocation(bounds.x + INCREMENT, bounds.y + INCREMENT);
    child.setVisible(true);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Centers the specified component on the parent and then makes it visible.
 * This method is mainly useful for windows, frames and dialogs. 
 * //  ww w  .j av  a  2  s  .c om
 * @param parent    The visible parent.
  * @param child     The child to display.
 */
public static void centerAndShow(Component parent, Component child) {
    if (parent == null || child == null)
        return;
    Rectangle bounds = parent.getBounds();
    Rectangle ed = child.getBounds();
    child.setLocation(bounds.x + (bounds.width - ed.width) / 2, bounds.y + (bounds.height - ed.height) / 2);
    child.setVisible(true);
}