Example usage for java.awt Component getLocationOnScreen

List of usage examples for java.awt Component getLocationOnScreen

Introduction

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

Prototype

public Point getLocationOnScreen() 

Source Link

Document

Gets the location of this component in the form of a point specifying the component's top-left corner in the screen's coordinate space.

Usage

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

/**
 * Traverses through components hierarchy and prepares screen shot for every component passed in
 * <code>componentImages</code> map except for branch root if <code>isRoot</code> is
 * <code>true</code>./*from www . jav a2 s  . c o  m*/
 * 
 * @param component
 *          the branch hierarchy root component.
 * @param componentImages
 *          the {@link Map} of components which screen shots should be made for. This map would be
 *          filled by prepared {@link java.awt.Image} instances.
 * @param rootComponent
 *          this branch hierarchy root component.
 */
static void makeShotsHierarchy(Component component, Map<Component, java.awt.Image> componentImages,
        Component rootComponent) throws Exception {
    if (componentImages.containsKey(component) && component != rootComponent) {
        BufferedImage thisComponentImage = (BufferedImage) createComponentShotAWT(component);
        // BUG in OS X (Java 1.6.0_24-b07-334-10M3326): Component.printAll() returns no image 
        // for AWT components and these components are not drawn on the JComponent container 
        // using the same printAll() method. 
        // The workaround is to hack into a native peer, get the native image and then paint it. 
        if (EnvironmentUtils.IS_MAC && !(component instanceof JComponent)) {
            int width = Math.max(1, component.getWidth());
            int height = Math.max(1, component.getHeight());
            Image nativeImage = OSSupport.get().makeShotAwt(component, width, height);
            if (nativeImage != null) {
                BufferedImage rootImage = (BufferedImage) componentImages.get(rootComponent);
                Point rootLocation = rootComponent.getLocationOnScreen();
                Point componentLocation = component.getLocationOnScreen();
                thisComponentImage = ImageUtils.convertToAWT(nativeImage.getImageData());
                rootImage.getGraphics().drawImage(thisComponentImage, componentLocation.x - rootLocation.x,
                        componentLocation.y - rootLocation.y, null);
            }
        }
        componentImages.put(component, thisComponentImage);
    }
    if (component instanceof Container) {
        Container container = (Container) component;
        for (Component childComponent : container.getComponents()) {
            makeShotsHierarchy(childComponent, componentImages, rootComponent);
        }
    }
}

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

public void showPupup(final Component component, final int relX, final int relY) {
    final Point xy = component.getLocationOnScreen();
    if (relX != 0 || relY != 0) {
        xy.translate(relX, relY);/*w  w w .  j a  v a2s  . c o m*/
    }
    this.showPopup(xy.x, xy.y);
}

From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java

private void actionModifierAxe(MouseEvent e, final int index) {

    if (index == -1)
        return;/*from w w  w.  j  a v a  2s.com*/

    Component comp = (Component) e.getSource();
    JFrame frame = (JFrame) SwingUtilities.getRoot(comp);

    this.windowChangeNom = new JWindow(frame);
    Container container = this.windowChangeNom.getContentPane();
    container.setLayout(new GridBagLayout());

    final GridBagConstraints c = new DefaultGridBagConstraints();
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 1;

    this.editedAxeIndex = index;
    this.text = new JTextField(" " + this.tabAxes.getTitleAt(index) + " ");
    this.text.setEditable(true);
    container.add(this.text, c);
    this.text.setBorder(null);
    // text.setBackground(this.tabAxes.getBackground());
    this.text.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent event) {

            if (event.getKeyCode() == KeyEvent.VK_ENTER) {
                validAxeText();
            }
        }

    });

    this.windowChangeNom.pack();

    int ecartY = this.tabAxes.getBoundsAt(index).height - this.text.getBounds().height + 2;
    int ecartX = this.tabAxes.getBoundsAt(index).width - this.text.getBounds().width;

    this.windowChangeNom.setLocation(
            comp.getLocationOnScreen().x + this.tabAxes.getBoundsAt(index).getLocation().x + ecartX / 2,
            comp.getLocationOnScreen().y + this.tabAxes.getBoundsAt(index).getLocation().y + ecartY / 2);

    this.windowChangeNom.setVisible(true);
}