Example usage for java.awt Point setLocation

List of usage examples for java.awt Point setLocation

Introduction

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

Prototype

public void setLocation(double x, double y) 

Source Link

Document

Sets the location of this point to the specified double coordinates.

Usage

From source file:Main.java

public static void main(String[] args) {
    Point p = new Point();

    p.setLocation(2.3D, 3.3D);
    System.out.println(p.toString());
}

From source file:Main.java

public static void main(String[] args) {
    Point p = new Point();

    p.setLocation(2.3D, 3.3D);
    System.out.println(p.getLocation());
}

From source file:Main.java

public static void main(String[] args) {
    Point p = new Point();

    p.setLocation(2, 3);
    System.out.println(p.toString());
}

From source file:Main.java

public static void main(String[] args) {
    Point p = new Point();

    p.setLocation(2.3D, 3.3D);
    System.out.println(p.getX());
    System.out.println(p.getY());
}

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  av  a2s. c  o  m*/
}

From source file:Main.java

/**
 * Calculates the position of a frame to be in the center of an other frame.
 *
 * @param parentFrame/*from   w w  w .ja  v a  2  s . c  om*/
 * @param frame
 * @return
 */
public static Point getCenter(final Component parentFrame, final Window frame) {
    final Point point = new Point();
    int x = 0, y = 0;

    if (parentFrame == null || frame == null) {
        point.setLocation(x, y);
        return point;
    }

    x = parentFrame.getLocation().x + parentFrame.getSize().width / 2 - frame.getSize().width / 2;
    y = parentFrame.getLocation().y + parentFrame.getSize().height / 2 - frame.getSize().height / 2;

    point.setLocation(x, y);

    return point;
}

From source file:Main.java

public static void setCenter(Component component, Component component1) {
    Point point;
    Dimension dimension;//w w w . j a v a  2s .c o  m
    if (component != null) {
        point = component.getLocation();
        dimension = component.getSize();
    } else {
        dimension = Toolkit.getDefaultToolkit().getScreenSize();
        point = new Point(0, 0);
    }
    Dimension dimension1 = Toolkit.getDefaultToolkit().getScreenSize();
    point.setLocation((double) point.x + dimension.getWidth() / 2D,
            (double) point.y + dimension.getHeight() / 2D);
    Point point1 = new Point(point.x - component1.getWidth() / 2, point.y - component1.getHeight() / 2);
    if (point1.y < 0)
        point1.y = 0;
    if (point1.x < 0)
        point1.y = 0;
    if (point1.x + component1.getWidth() > dimension1.width)
        point1.x = dimension1.width - component1.getWidth();
    if (point1.y + component1.getHeight() > dimension1.height)
        point1.y = dimension1.height - component1.getHeight();
    component1.setLocation(point1);
}

From source file:nl.b3p.imagetool.ImageTool.java

private static Point calculateCenter(Shape shape, int srid, Bbox bbox, int width, int height) throws Exception {
    Point centerPoint = new Point();
    double x = shape.getBounds2D().getCenterX();
    double y = shape.getBounds2D().getCenterY();
    centerPoint.setLocation(x, y);
    centerPoint = transformToScreen(centerPoint, srid, bbox, width, height);
    return centerPoint;
}

From source file:net.chaosserver.timelord.swingui.SwingUtil.java

/**
 * Repair location is designed to detect if a box is partially
 * off-screen and move the box back onto the screen.
 *
 * @param component component to repair/*from  w w w  . ja  va2  s . com*/
 */
public static void repairLocation(Component component) {
    Point locationPoint = component.getLocation();
    Point locationOnScreenPoint = null;
    if (component.isVisible()) {
        locationOnScreenPoint = component.getLocationOnScreen();
    }
    Dimension componentSize = component.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    if (log.isDebugEnabled()) {
        log.debug("Repairing location on [" + component.getClass().getName() + "].  Original location point = ["
                + locationPoint + "] and location on screen point = [" + locationOnScreenPoint
                + "].  The screen size is [" + screenSize + "] and the component size is [" + componentSize
                + "]");
    }

    // Is the dialog to far to the left?  Then fix.
    if (locationPoint.getX() < 0) {
        locationPoint.setLocation(0, locationPoint.getY());
    }
    if (locationPoint.getY() < 0) {
        locationPoint.setLocation(locationPoint.getX(), 0);
    }
    // component.setLocation(locationPoint);

    // Is the dialog too wide?
    if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) {

        componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX());
    }
    if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) {

        componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY());
    }

    // component.setSize(componentSize);
}

From source file:net.chaosserver.timelord.swingui.PreviousDayPanel.java

/**
 * Listens for action from this panel. If the pick date button is choosen
 * displays a Calendar allowing a user to select a date for display.
 *
 * @param evt the event triggering things
 *//*  w  ww. j  a  v  a 2s .c om*/
public void actionPerformed(ActionEvent evt) {
    if (ACTION_PICK_DAY.equals(evt.getActionCommand())) {
        Frame ownerFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
        JCalendarDialog calendarDialog = new JCalendarDialog(ownerFrame, getDisplayDate());

        calendarDialog.pack();

        Point ownerFrameLocation = ownerFrame.getLocation();
        ownerFrameLocation.setLocation(ownerFrameLocation.getX() + LayoutConstants.CHILD_FRAME_X_OFFSET,
                ownerFrameLocation.getY() + LayoutConstants.CHILD_FRAME_Y_OFFSET);

        calendarDialog.setLocation(ownerFrameLocation);
        calendarDialog.setVisible(true);

        Date choosenDate = calendarDialog.getChoosenDate();

        if (choosenDate != null) {
            setDisplayDate(choosenDate);
        }
    }
}