Example usage for java.awt Rectangle getHeight

List of usage examples for java.awt Rectangle getHeight

Introduction

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

Prototype

public double getHeight() 

Source Link

Document

Returns the height of the bounding Rectangle in double precision.

Usage

From source file:Main.java

public static void main(String[] args) {
    int ROWS = 100;
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(new JLabel("Thanks for helping out. Use tab to move around."));
    for (int i = 0; i < ROWS; i++) {
        JTextField field = new JTextField("" + i);
        field.setName("field#" + i);
        content.add(field);/*from www.ja v a2 s.c  om*/
    }
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner",
            new PropertyChangeListener() {
                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (!(evt.getNewValue() instanceof JComponent)) {
                        return;
                    }
                    JViewport viewport = (JViewport) content.getParent();
                    JComponent focused = (JComponent) evt.getNewValue();
                    if (content.isAncestorOf(focused)) {
                        Rectangle rect = focused.getBounds();
                        Rectangle r2 = viewport.getVisibleRect();
                        content.scrollRectToVisible(
                                new Rectangle(rect.x, rect.y, (int) r2.getWidth(), (int) r2.getHeight()));
                    }
                }
            });
    JFrame window = new JFrame();
    window.setContentPane(new JScrollPane(content));
    window.setSize(200, 200);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.setVisible(true);
}

From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java

public static void main(String args[]) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                Color SELECTED_COLOR = new Color(184, 204, 217);
                Color BASE_COLOR = new Color(220, 231, 243, 50);
                Color ALT_COLOR = new Color(220, 231, 243, 115);

                //                    Insets MENU_INSETS = new Insets(1,12,2,5);//default values
                //                    Font MENU_FONT = new Font("SansSerif ", Font.PLAIN, 12);//default values

                //                    UIManager.put("nimbusBase", BASE_COLOR);
                UIManager.put("nimbusSelection", SELECTED_COLOR);
                UIManager.put("nimbusSelectionBackground", SELECTED_COLOR);
                UIManager.put("Menu[Enabled+Selected].backgroundPainter", SELECTED_COLOR);

                //override defaults
                for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                    if (info.getName().equals("Nimbus")) {
                        UIManager.setLookAndFeel(info.getClassName());
                        UIDefaults defaults = UIManager.getLookAndFeelDefaults();
                        defaults.put("Table.gridColor", Color.lightGray);
                        defaults.put("Table.disabled", false);
                        defaults.put("Table.showGrid", true);
                        defaults.put("Table.intercellSpacing", new Dimension(1, 1));
                        break;
                    }/*from w w w . j  ava 2 s . com*/
                }

                //                    UIManager.put("TitledBorder.position", TitledBorder.TOP);

                //                    UIManager.put("Table.showGrid", true);
                //                    UIManager.put("Table.gridColor", Color.RED);
                //                    UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
            } catch (UnsupportedLookAndFeelException ulafe) {
                //                    logger.fatal("Substance failed to set", ulafe);
            } catch (Exception ex) {
                //                    logger.fatal(ex.getMessage(), ex);
            }

            JFrame frame = new Jmetrik();

            //            set window to maximum size but account for taskbar
            GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
            Rectangle rect = env.getMaximumWindowBounds();
            int width = Double.valueOf(rect.getWidth() - 1.0).intValue();
            int height = Double.valueOf(rect.getHeight() - 1.0).intValue();
            frame.setMaximizedBounds(new Rectangle(0, 0, width, height));
            frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            frame.pack();
            //            frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
            frame.setVisible(true);

            //check for updates to jmetrik
            ((Jmetrik) frame).checkForUpdates();
        }
    });

}

From source file:Main.java

/**
 * Returns the center position of the specified component.
 *//*from w  ww . java2  s.co  m*/
public static Point2D.Double getCenter(Component c) {
    if (c != null) {
        final Rectangle r = c.getBounds();
        return new Point2D.Double(r.getX() + (r.getWidth() / 2d), r.getY() + (r.getHeight() / 2d));
    }

    return new Point2D.Double(0d, 0d);
}

From source file:Main.java

public static void centerComponent(Component relativeTo, Component toCenter) {
    if (relativeTo == null) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screenSize = tk.getScreenSize();
        int screenHeight = screenSize.height;
        int screenWidth = screenSize.width;
        toCenter.setLocation((screenWidth / 2) - (toCenter.getSize().width / 2),
                (screenHeight / 2) - (toCenter.getSize().height / 2));
    } else {/*w  ww. j ava2 s  .  co  m*/
        Point loc = relativeTo.getLocationOnScreen();
        Rectangle bounds = relativeTo.getBounds();
        toCenter.setLocation((int) (loc.x + bounds.getWidth() / 2) - (toCenter.getWidth() / 2),
                (int) (loc.y + bounds.getHeight() / 2) - (toCenter.getHeight() / 2));

    }
}

From source file:Main.java

/**
 * Centers a component on its parent./*from  w  w w. j  a va  2 s  . c  o m*/
 *
 * @param component
 */
public static void centerInParent(Component component) {
    Container parent = component.getParent();
    if (parent != null) {
        Rectangle parentBounds = parent.getBounds();
        Rectangle dialogBounds = new Rectangle(
                (int) (parentBounds.getMinX() + parentBounds.getWidth() / 2 - component.getWidth() / 2),
                (int) (parentBounds.getMinY() + parentBounds.getHeight() / 2 - component.getHeight() / 2),
                component.getWidth(), component.getHeight());
        //dialog.setBounds( dialogBounds );
        component.setLocation(dialogBounds.x, dialogBounds.y);
    }
}

From source file:com.jaeksoft.searchlib.util.ImageUtils.java

public static final void yellowHighlight(Image image, Collection<Rectangle> boxes, float outsetFactor) {
    if (CollectionUtils.isEmpty(boxes))
        return;//  w  ww.j  av a  2s.com
    Graphics2D g2d = (Graphics2D) image.getGraphics();
    g2d.setPaint(Color.YELLOW);
    Composite originalComposite = g2d.getComposite();
    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
    g2d.setComposite(ac);
    for (Rectangle box : boxes) {
        if (outsetFactor != 1.0F) {
            box = new Rectangle(box);
            box.grow((int) (box.getHeight() * outsetFactor), (int) (box.getWidth() * outsetFactor));
        }
        g2d.fill(box);
    }
    g2d.setComposite(originalComposite);
}

From source file:com.SCI.centraltoko.utility.UtilityTools.java

public static void scroolTorect(JTable tabel, int nextRow) {
    Rectangle currenVisible = tabel.getVisibleRect();
    Rectangle scroolTorect = tabel.getCellRect(nextRow, 0, true);
    if (scroolTorect.getY() > currenVisible.getY() + currenVisible.getHeight()) {
        scroolTorect.setLocation(0,//  w ww.j av  a2  s  .  c  o  m
                (int) (scroolTorect.getY() + currenVisible.getHeight() - scroolTorect.getHeight()));
    }
    tabel.scrollRectToVisible(scroolTorect);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Rectangle r = new Rectangle(100, 100, 200, 200);

    g2.fill(r);//  w  ww .  ja v  a2 s .  c om
    System.out.println(r.getHeight());

}

From source file:net.sf.mcf2pdf.mcfelements.util.ImageUtil.java

/**
 * Rotates the given buffered image by the given angle, and returns a newly
 * created image, containing the rotated image.
 *
 * @param img Image to rotate./*from   w w w .  j  a  va2  s .  co m*/
 * @param angle Angle, in radians, by which to rotate the image.
 * @param drawOffset Receives the offset which is required to draw the image,
 * relative to the original (0,0) corner, so that the center of the image is
 * still on the same position.
 *
 * @return A newly created image containing the rotated image.
 */
public static BufferedImage rotateImage(BufferedImage img, float angle, Point drawOffset) {
    int w = img.getWidth();
    int h = img.getHeight();

    AffineTransform tf = AffineTransform.getRotateInstance(angle, w / 2.0, h / 2.0);

    // get coordinates for all corners to determine real image size
    Point2D[] ptSrc = new Point2D[4];
    ptSrc[0] = new Point(0, 0);
    ptSrc[1] = new Point(w, 0);
    ptSrc[2] = new Point(w, h);
    ptSrc[3] = new Point(0, h);

    Point2D[] ptTgt = new Point2D[4];
    tf.transform(ptSrc, 0, ptTgt, 0, ptSrc.length);

    Rectangle rc = new Rectangle(0, 0, w, h);

    for (Point2D p : ptTgt) {
        if (p.getX() < rc.x) {
            rc.width += rc.x - p.getX();
            rc.x = (int) p.getX();
        }
        if (p.getY() < rc.y) {
            rc.height += rc.y - p.getY();
            rc.y = (int) p.getY();
        }
        if (p.getX() > rc.x + rc.width)
            rc.width = (int) (p.getX() - rc.x);
        if (p.getY() > rc.y + rc.height)
            rc.height = (int) (p.getY() - rc.y);
    }

    BufferedImage imgTgt = new BufferedImage(rc.width, rc.height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = imgTgt.createGraphics();

    // create a NEW rotation transformation around new center
    tf = AffineTransform.getRotateInstance(angle, rc.getWidth() / 2, rc.getHeight() / 2);
    g2d.setTransform(tf);
    g2d.drawImage(img, -rc.x, -rc.y, null);
    g2d.dispose();

    drawOffset.x += rc.x;
    drawOffset.y += rc.y;

    return imgTgt;
}

From source file:com.o2d.pkayjava.editor.Main.java

private void startLoadingEditor() {
    //first, kill off the splash
    if (!(SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_UNIX)) {
        splash.kill();/*w  w  w  .j ava 2  s  . c o  m*/
    }

    Overlap2D overlap2D = new Overlap2D();
    Rectangle maximumWindowBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    double width = maximumWindowBounds.getWidth();
    double height = maximumWindowBounds.getHeight();

    if (SystemUtils.IS_OS_MAC_OSX || SystemUtils.IS_OS_MAC) {
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Overlap2D");
        JglfwApplicationConfiguration config = new JglfwApplicationConfiguration();
        config.width = (int) (width);
        config.height = (int) (height - height * .04);
        config.backgroundFPS = 0;
        config.title = "Overlap2D - Public Alpha v" + AppConfig.getInstance().version;
        new JglfwApplication(overlap2D, config);
    } else {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.title = "Overlap2D - Public Alpha v" + AppConfig.getInstance().version;
        config.fullscreen = true;
        config.resizable = false;
        config.width = (int) (width);
        config.height = (int) (height - height * .04);
        config.backgroundFPS = 0;
        mainFrame = new LwjglFrame(overlap2D, config);
        mainFrame.setExtendedState(mainFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        toggleVisible();

        // subscribe to file dropping notifications, currently windows only
        DropTarget dropTarget = new DropTarget(mainFrame, new FileDropListener());
    }

    if (!SystemUtils.IS_OS_UNIX) {
        // no aesthetics for linux users I guess..
        setIcon();
    }

}