Beispiel #1
0
  /**
   * We generally draw lines to/from the <I>center</I> of components; this method finds the center
   * of the argument's enclosing rectangle
   *
   * @return Point at the center of <CODE>c</CODE>
   * @param c The component whose center point we wish to determine
   */
  protected Point getCenterLocation(Component c) {

    Point p1 = new Point();
    Point p2 = new Point();

    // start with the relative location...
    c.getLocation(p1);
    // get to the middle of the fractionsLabel
    Dimension d = c.getSize();
    p1.x += d.width / 2;
    p1.y += d.height / 2;

    Component parent = c.getParent();
    // System.err.println("parent=" + parent);

    while (parent != null) {
      parent.getLocation(p2);
      p1.x += p2.x;
      p1.y += p2.y;

      if (STOP.equals(parent.getName())) break;

      parent = parent.getParent();
    }
    return p1;
  }
Beispiel #2
0
 /**
  * Changes the frame's location to a more central screen location
  *
  * @param frame the frame to be moved
  * @param X how far right to move the frame
  * @param Y how far down to move the frame
  */
 public static void changeFrameLocation(Component frame, int X, int Y) {
   Point location = frame.getLocation(); // the window's current location
   // move the window over and down a certain amount of pixels
   location.translate(X, Y);
   // set the location
   frame.setLocation(location);
 }
 public void componentMoved(ComponentEvent evt) {
   Component component = evt.getComponent();
   Point point = component.getLocation();
   if (point.y < 0) {
     component.setBounds(point.x, 0, component.getWidth(), component.getHeight());
   }
 }
Beispiel #4
0
 public static void center(Component c, Component rel) {
   if (rel != null) {
     c.setLocation(
         rel.getLocation().x + rel.getSize().width / 2 - c.getSize().width / 2,
         rel.getLocation().y + rel.getSize().height / 2 - c.getSize().height / 2);
   } else {
     c.setLocation(
         Toolkit.getDefaultToolkit().getScreenSize().width / 2 - c.getSize().width / 2,
         +Toolkit.getDefaultToolkit().getScreenSize().height / 2 - c.getSize().height / 2);
   }
 }
 public void paint(Graphics g1) {
   Graphics2D g = (Graphics2D) g1;
   Component c;
   Point p;
   paintComponent(g);
   for (int i = 0; i < getComponentCount(); i++) {
     AffineTransform save = g.getTransform();
     c = getComponent(i);
     p = c.getLocation();
     g.translate((int) p.getX(), (int) p.getY());
     c.paint(g);
     g.setTransform(save);
   }
 }