Java Screen Center setCenteredRectangle(int rectangleWidth, int rectangleHeight)

Here you can find the source of setCenteredRectangle(int rectangleWidth, int rectangleHeight)

Description

set Centered Rectangle

License

Open Source License

Declaration

public static Rectangle setCenteredRectangle(int rectangleWidth,
            int rectangleHeight) 

Method Source Code

//package com.java2s;
import java.awt.Dimension;

import java.awt.Rectangle;
import java.awt.Toolkit;

public class Main {
    public static Rectangle setCenteredRectangle(int rectangleWidth,
            int rectangleHeight) {
        Dimension screenDimensions = Toolkit.getDefaultToolkit()
                .getScreenSize();//from  w  ww . jav a 2s  . c  o  m
        int xCenter = (screenDimensions.width - rectangleWidth) / 2;
        int yCenter = (screenDimensions.height - rectangleHeight) / 2;

        return new Rectangle(xCenter, yCenter, rectangleWidth,
                rectangleHeight);
    }
}

Related

  1. setCenter(Component comp, Component parent)
  2. setCenter(Component component)
  3. setCenter(Component component, Component component1)
  4. setCenteredCoordSystem(Graphics2D g, Component comp, double unitx, double unity)
  5. setCenteredInScreen(Component frame)
  6. setCenterLocation(final Window window)
  7. setCenterPosition(final Frame frame)
  8. setComponentLocationOnCenter(Component component)
  9. setLocationCentral(final Component component)