Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

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

Prototype

public Rectangle() 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is at (0, 0) in the coordinate space, and whose width and height are both zero.

Usage

From source file:Main.java

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    Rectangle vBounds = new Rectangle();

    GraphicsDevice[] gdArray = ge.getScreenDevices();

    for (int i = 0; i < gdArray.length; i++) {
        GraphicsDevice gd = gdArray[i];

        GraphicsConfiguration[] gcArray = gd.getConfigurations();

        for (int j = 0; j < gcArray.length; j++)
            vBounds = vBounds.union(gcArray[j].getBounds());
    }/*from   www .ja  v a2s.co  m*/

    Point origin = vBounds.getLocation();
    System.out.println("Virtual x = " + origin.x);
    System.out.println("Virtual y = " + origin.y);

    Dimension size = vBounds.getSize();
    System.out.println("Virtual width = " + size.width);
    System.out.println("Virtual height = " + size.height);
}

From source file:MainClass.java

public static void main(String[] args) {
    GraphicsEnvironment ge;/*from  w w w .  ja  v a 2 s .c o m*/
    ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

    Rectangle vBounds = new Rectangle();

    GraphicsDevice[] gdArray = ge.getScreenDevices();

    for (int i = 0; i < gdArray.length; i++) {
        GraphicsDevice gd = gdArray[i];

        GraphicsConfiguration[] gcArray = gd.getConfigurations();

        for (int j = 0; j < gcArray.length; j++)
            vBounds = vBounds.union(gcArray[j].getBounds());
    }

    Point origin = vBounds.getLocation();
    System.out.println("Virtual x = " + origin.x);
    System.out.println("Virtual y = " + origin.y);

    Dimension size = vBounds.getSize();
    System.out.println("Virtual width = " + size.width);
    System.out.println("Virtual height = " + size.height);
}

From source file:GuiScreens.java

public static void main(String[] args) {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    JFrame frame[][] = new JFrame[gs.length][];
    for (int j = 0; j < gs.length; j++) {
        GraphicsDevice gd = gs[j];
        System.out.println("Device " + j + ": " + gd);
        GraphicsConfiguration[] gc = gd.getConfigurations();
        frame[j] = new JFrame[gc.length];

        for (int i = 0; i < gc.length; i++) {
            System.out.println("  Configuration " + i + ": " + gc[i]);
            System.out.println("    Bounds: " + gc[i].getBounds());
            virtualBounds = virtualBounds.union(gc[i].getBounds());
            frame[j][i] = new JFrame("Config: " + i, gc[i]);
            frame[j][i].setBounds(50, 50, 400, 100);
            frame[j][i].setLocation((int) gc[i].getBounds().getX() + 50, (int) gc[i].getBounds().getY() + 50);
            frame[j][i].getContentPane().add(new JTextArea("Config:\n" + gc[i]));
            frame[j][i].setVisible(true);
        }//  w  w  w .  j a  v  a 2s.c o m
        System.out.println("Overall bounds: " + virtualBounds);
    }
}

From source file:SampleConstructor.java

public static void main(String[] args) {
    Rectangle r = new Rectangle();
    showConstructors(r);
}

From source file:Main.java

public static void main(String[] args) {
    JTextArea cmp = new JTextArea();
    String str = "a";
    for (int i = 0; i < 20; i++) {
        cmp.append(str + str + "\n");
    }/*from w w w . ja  va  2 s  . c  o  m*/
    JScrollPane scrollPane = new JScrollPane(cmp);
    scrollPane.setComponentZOrder(scrollPane.getVerticalScrollBar(), 0);
    scrollPane.setComponentZOrder(scrollPane.getViewport(), 1);
    scrollPane.getVerticalScrollBar().setOpaque(false);

    scrollPane.setLayout(new ScrollPaneLayout() {
        @Override
        public void layoutContainer(Container parent) {
            JScrollPane scrollPane = (JScrollPane) parent;

            Rectangle availR = scrollPane.getBounds();
            availR.x = availR.y = 0;

            Insets parentInsets = parent.getInsets();
            availR.x = parentInsets.left;
            availR.y = parentInsets.top;
            availR.width -= parentInsets.left + parentInsets.right;
            availR.height -= parentInsets.top + parentInsets.bottom;

            Rectangle vsbR = new Rectangle();
            vsbR.width = 12;
            vsbR.height = availR.height;
            vsbR.x = availR.x + availR.width - vsbR.width;
            vsbR.y = availR.y;

            if (viewport != null) {
                viewport.setBounds(availR);
            }
            if (vsb != null) {
                vsb.setVisible(true);
                vsb.setBounds(vsbR);
            }
        }
    });
    scrollPane.getVerticalScrollBar().setUI(new MyScrollBarUI());

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(scrollPane);
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:Main.java

public static Rectangle computeVirtualGraphicsBounds() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (GraphicsDevice gd : gs) {
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        virtualBounds = virtualBounds.union(gc.getBounds());
    }/*from  w w w .  j  a v a 2 s  .  c  o  m*/
    return virtualBounds;
}

From source file:Main.java

public static void centerOnScreen(Window w, Window parent) {
    Rectangle r = new Rectangle();
    if (parent == null) {
        r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
    } else {//from  www. ja va 2 s.  c o  m
        r.setLocation(parent.getLocation());
        r.setSize(parent.getSize());
    }
    // Determine the new location of the alert
    int x = r.x + (r.width - w.getWidth()) / 2;
    int y = r.y + (r.height - w.getHeight()) / 2;
    // Move the alert
    w.setLocation(x, y);
}

From source file:Main.java

/**
 * Finds the real bounds of the component relative to the root Window
 *
 * @param container The container to find the bounds for.
 * @return The real bounds of the container.
 *///  w  ww.  j ava2s. c o m
public static Rectangle getRealBounds(Container container) {
    return getRealBounds(container, new Rectangle());
}

From source file:Main.java

public static Rectangle getTextRectangle(JLabel label) {

    String text = label.getText();
    Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();

    if ((icon == null) && (text == null)) {
        return null;
    }//  www  .  j  a  va2s. com

    Rectangle paintIconR = new Rectangle();
    Rectangle paintTextR = new Rectangle();
    Rectangle paintViewR = new Rectangle();
    Insets paintViewInsets = new Insets(0, 0, 0, 0);

    paintViewInsets = label.getInsets(paintViewInsets);
    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;
    paintViewR.width = label.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.height = label.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    Graphics g = label.getGraphics();
    if (g == null) {
        return null;
    }
    String clippedText = SwingUtilities.layoutCompoundLabel(label, g.getFontMetrics(), text, icon,
            label.getVerticalAlignment(), label.getHorizontalAlignment(), label.getVerticalTextPosition(),
            label.getHorizontalTextPosition(), paintViewR, paintIconR, paintTextR, label.getIconTextGap());

    return paintTextR;
}

From source file:Main.java

/**
 * returns the virtual screensize in a multimonitor system
 * /*from w ww .  jav  a 2s.co  m*/
 * @return
 */
public static Dimension getVirtualScreenSize() {
    Rectangle virtualBounds = new Rectangle();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();
    for (int j = 0; j < gs.length; j++) {
        GraphicsDevice gd = gs[j];
        GraphicsConfiguration[] gc = gd.getConfigurations();
        for (int i = 0; i < gc.length; i++) {
            virtualBounds = virtualBounds.union(gc[i].getBounds());
        }
    }
    return virtualBounds.getSize();
}