Java JComponent Container getWindowLocation(JComponent start)

Here you can find the source of getWindowLocation(JComponent start)

Description

search of the hierarcy of components for an instance of a given class

License

Apache License

Parameter

Parameter Description
start - starting component
theClass - required class

Return

possibly null component - null says no ancestor found

Declaration

public static Point getWindowLocation(JComponent start) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import javax.swing.*;

import java.awt.*;

public class Main {
    /**/*from  ww  w.  j a va2s.  c  o m*/
     * search of the hierarcy of components for an instance of a given class
     *
     * @param start    - starting component
     * @param theClass - required class
     * @return possibly null component - null says no ancestor found
     */
    public static Point getWindowLocation(JComponent start) {
        Point loc = start.getLocation();
        Container parent = start.getParent();
        if (parent == null)
            return loc;
        if (parent instanceof JComponent) {
            Point ancestorLoc = getWindowLocation((JComponent) parent);
            return new Point(loc.x + ancestorLoc.x, loc.y + ancestorLoc.y);
        } else {
            return loc;
        }

    }
}

Related

  1. getStringValue(JComponent component)
  2. getTopAncestor(JComponent start)
  3. getTopLevelContainer(JComponent component)
  4. getWindow(final JComponent comp)
  5. getWindow(JComponent c)
  6. invokeRepaintOnLayeredRoot(Component leaf, boolean everything)
  7. isCopyEnabled(JComponent targetComponent)
  8. isPasteEnabled(JComponent targetComponent)
  9. rootPaneForComponent(Component comp)