Java Code Examples for java.awt.Component#getLocation()

The following examples show how to use java.awt.Component#getLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 2
Source File: MotifDesktopPaneUI.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 3
Source File: MotifDesktopPaneUI.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 4
Source File: MotifDesktopPaneUI.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 5
Source File: MotifDesktopPaneUI.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 6
Source File: MotifDesktopPaneUI.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 7
Source File: JChoice.java    From gate-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Dimension getPreferredSize() {
  Dimension size = super.getPreferredSize();
  if(getItemCount() <= maximumFastChoices && size.width > maximumWidth) {
    setSize(maximumWidth, Integer.MAX_VALUE);
    doLayout();
    int compCnt = getComponentCount();
    if(compCnt > 0) {
      Component lastComp = getComponent(compCnt - 1);
      Point compLoc = lastComp.getLocation();
      Dimension compSize = lastComp.getSize();
      size.width = maximumWidth;
      size.height = compLoc.y + compSize.height + getInsets().bottom;
    }
  }
  return size;
}
 
Example 8
Source File: MotifDesktopPaneUI.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 9
Source File: UtilityGeometry.java    From Ardulink-2 with Apache License 2.0 6 votes vote down vote up
public static void setAlignmentCentered(Component component, Component referredComponent) {
	if(referredComponent == null) {
		referredComponent = SwingUtilities.getRoot(component);
	}
	Point rootLocation = referredComponent.getLocation();
	Dimension rootDimension = referredComponent.getSize();
	Dimension componentDimension = component.getSize();
	
	Point componentLocation = new Point(rootLocation);
	int dx = (rootDimension.width - componentDimension.width) / 2;
	int dy = (rootDimension.height - componentDimension.height) / 2;
	componentLocation.translate(dx, dy);
	
	component.setLocation(componentLocation);
	
}
 
Example 10
Source File: MotifDesktopPaneUI.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 11
Source File: MFlowLayout.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Dimension preferredLayoutSize(Container target) {
  synchronized (target.getTreeLock()) {
    Dimension dim = new Dimension(0, 0);

    for (int i = 0; i < target.getComponentCount(); i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getPreferredSize();

        // original
        // dim.height = Math.max(dim.height, d.height);
        // if (i > 0) { dim.width += hgap; }
        // dim.width += d.width;

        // new way
        Point p = m.getLocation();
        dim.width = Math.max(dim.width, p.x + d.width);
        dim.height = Math.max(dim.height, p.y + d.height);
      }
    }
    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right + getHgap() * 2;
    dim.height += insets.top + insets.bottom + getVgap() * 2;
    return dim;
  }
}
 
Example 12
Source File: DrawTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 13
Source File: MotifDesktopPaneUI.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 14
Source File: MotifDesktopPaneUI.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 15
Source File: DrawTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 16
Source File: MotifDesktopPaneUI.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
protected JInternalFrame.JDesktopIcon getIconAt(JDesktopPane desktop,
    JInternalFrame.JDesktopIcon icon, int x, int y) {

    JInternalFrame.JDesktopIcon currentIcon = null;
    Component[] components = desktop.getComponents();

    for (int i=0; i<components.length; i++) {
        Component comp = components[i];
        if (comp instanceof JInternalFrame.JDesktopIcon &&
            comp != icon) {

            Point p = comp.getLocation();
            if (p.x == x && p.y == y) {
                return (JInternalFrame.JDesktopIcon)comp;
            }
        }
    }
    return null;
}
 
Example 17
Source File: DrawTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 18
Source File: DrawTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 19
Source File: DrawTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    Rectangle r = getBounds();
    g.setColor(Color.lightGray);
    g.draw3DRect(0, 0, r.width, r.height, false);

    int n = getComponentCount();
    for (int i = 0; i < n; i++) {
        Component comp = getComponent(i);
        if (comp instanceof Checkbox) {
            Point loc = comp.getLocation();
            Dimension d = comp.getSize();
            g.setColor(comp.getForeground());
            g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
        }
    }
}
 
Example 20
Source File: Show.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
public static void centrateComponent(Component parent, Component c) {
    if (parent == null) {
        centrateComponent(c);
    } else {
        Dimension dimParent = parent.getSize();
        Point p = parent.getLocation();
        Dimension dimComp = c.getSize();
        c.setLocation(p.x + ((dimParent.width - dimComp.width) / 2),
                p.y + ((dimParent.height - dimComp.height) / 2));
    }
}