Example usage for java.awt Component getHeight

List of usage examples for java.awt Component getHeight

Introduction

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

Prototype

public int getHeight() 

Source Link

Document

Returns the current height of this component.

Usage

From source file:Main.java

public static void addMiddleButtonDragSupport(Component targetComponent) {
    MouseInputAdapter mia = new MouseInputAdapter() {
        int m_XDifference, m_YDifference;
        boolean m_dragging = false;

        public void mouseDragged(MouseEvent e) {
            if (!m_dragging)
                return;

            Component target = e.getComponent();
            Container c = target.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - m_XDifference);
                int newY = p.y - (e.getY() - m_YDifference);

                int maxX = target.getWidth() - jv.getWidth();
                int maxY = target.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;//  w  w  w .j a  v a2s  .c  om
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        Cursor oldCursor;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                m_dragging = true;
                oldCursor = e.getComponent().getCursor();
                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                m_XDifference = e.getX();
                m_YDifference = e.getY();
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (m_dragging) {
                e.getComponent().setCursor(oldCursor);
                m_dragging = false;
            }
        }
    };
    targetComponent.addMouseMotionListener(mia);
    targetComponent.addMouseListener(mia);
}

From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java

public static void showPopup(@Nonnull final String text, @Nonnull final MessageType type) {
    SwingUtils.safeSwing(new Runnable() {
        @Override//from  w  ww  . ja  va  2  s  .  co  m
        public void run() {
            final JBPopupFactory factory = JBPopupFactory.getInstance();
            final BalloonBuilder builder = factory
                    .createHtmlTextBalloonBuilder(StringEscapeUtils.escapeHtml(text), type, null);
            final Balloon balloon = builder.createBalloon();
            balloon.setAnimationEnabled(true);
            final Component frame = WindowManager.getInstance().findVisibleFrame();
            if (frame != null)
                balloon.show(new RelativePoint(frame, new Point(frame.getWidth(), frame.getHeight())),
                        Balloon.Position.below);
        }
    });
}

From source file:Main.java

public static void setCenter(Component component, Component component1) {
    Point point;/*from www .  ja  va2s . com*/
    Dimension dimension;
    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:Main.java

public static void centralizeComponent(Component component, Component otherComponent) {

    Dimension othersDimension = null;
    Point othersLocation = null;/*w  ww  . ja  v a2  s.  c o m*/
    if (otherComponent == null || !otherComponent.isVisible()) {
        othersDimension = Toolkit.getDefaultToolkit().getScreenSize();
        othersLocation = new Point(0, 0);
    } else {
        othersDimension = otherComponent.getSize();
        othersLocation = otherComponent.getLocation();
    }
    Point centerPoint = new Point(
            (int) Math.round(othersDimension.width / HALF - component.getWidth() / HALF) + othersLocation.x,
            (int) Math.round(othersDimension.height / HALF - component.getHeight() / HALF) + othersLocation.y);
    component.setLocation(centerPoint);
}

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 {/*from  w w  w. j  ava  2  s  . c  o 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:com.simiacryptus.util.Util.java

/**
 * To image buffered image./*from   ww w .  j a va  2  s  .  c  o  m*/
 *
 * @param component the component
 * @return the buffered image
 */
public static BufferedImage toImage(@javax.annotation.Nonnull final Component component) {
    try {
        com.simiacryptus.util.Util.layout(component);
        @javax.annotation.Nonnull
        final BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(),
                BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics2D g = img.createGraphics();
        g.setColor(component.getForeground());
        g.setFont(component.getFont());
        component.print(g);
        return img;
    } catch (@javax.annotation.Nonnull final Exception e) {
        return null;
    }
}

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

/**
 * Centres the dialog over the component ensuring that the dialog will be
 * within the usable area of the screen (i.e. excluding native task bars,
 * menus bars etc).//from   w  ww . j a v a 2s  . c  om
 *
 * @param parent The component over which the dialog should be centred.
 * @param dialog The dialog to be positioned.
 */
public static void setComponentRelativeLocation(Component parent, Component dialog) {
    // First make sure it is not too big
    resizeComponentToScreen(dialog);

    // Get the maximum window size to account for taskbars etc
    Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
    Point centreOfParent = new Point(parent.getWidth() / 2, parent.getHeight() / 2);
    SwingUtilities.convertPointToScreen(centreOfParent, parent);
    // Default to centre of parent
    Point location = new Point(centreOfParent.x - (dialog.getWidth() / 2),
            centreOfParent.y - (dialog.getHeight() / 2));
    // Adjust so it fits on the screen
    if ((location.x + dialog.getWidth()) > (screenBounds.width + screenBounds.x)) {
        location.x -= (location.x + dialog.getWidth()) - (screenBounds.width + screenBounds.x);
    }
    if (location.x < screenBounds.x) {
        location.x = screenBounds.x;
    }
    if ((location.y + dialog.getHeight()) > (screenBounds.height + screenBounds.y)) {
        location.y -= (location.y + dialog.getHeight()) - (screenBounds.height + screenBounds.y);
    }
    if (location.y < screenBounds.y) {
        location.y = screenBounds.y;
    }
    dialog.setLocation(location);
}

From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java

/**
 * @return the {@link java.awt.Image} of given {@link Component}. Must be called from AWT disp
 *         thread.//from ww w  .  jav a2 s.com
 */
static java.awt.Image createComponentShotAWT(final Component component) throws Exception {
    Assert.isNotNull(component);
    // prepare sizes
    final int componentWidth = component.getWidth();
    final int componentHeight = component.getHeight();
    final int imageWidth = Math.max(1, componentWidth);
    final int imageHeight = Math.max(1, componentHeight);
    // prepare empty image
    final BufferedImage componentImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
    // If actual size on component is zero, then we are done.
    if (componentWidth == 0 || componentHeight == 0) {
        return componentImage;
    }
    // some components like JLabel are transparent by default and printing it separately gives
    // bad results like invalid background color. The workaround is to set opacity property and
    // restore old value back when all done.
    ComponentShotConfigurator shotConfigurator = new ComponentShotConfigurator(component);
    try {
        // Linux only: it seems that printAll() should be invoked in AWT dispatch thread 
        // to prevent deadlocks between main thread and AWT event queue.
        // See also SwingUtils.invokeLaterAndWait().
        runInDispatchThread(new Runnable() {
            public void run() {
                component.printAll(componentImage.getGraphics());
            }
        });
    } finally {
        shotConfigurator.dispose();
    }
    // convert into SWT image
    return componentImage;
}

From source file:Main.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    System.out.println(c.getWidth() + " " + c.getHeight() + " " + x + " " + y);
}

From source file:org.monkeys.gui.PopupWindow.java

public void showPupup(final Component component) {
    this.showPupup(component, 0, component.getHeight() + 2);
}