Beispiel #1
0
 public static void setPositionRelativeToParent(
     Window w, Component parent, int hOffset, int vOffset) {
   try {
     Point p = parent.getLocationOnScreen();
     int x = (int) p.getX() + hOffset;
     int y = (int) p.getY() + vOffset;
     w.setLocation(x, y);
     w.pack();
   } catch (Throwable t) {
   }
 }
Beispiel #2
0
    @Override
    public Dimension getPreferredSize() {
      final Component focusOwner =
          KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
      Point p = null;
      if (focusOwner != null && focusOwner.isShowing()) {
        p = focusOwner.getLocationOnScreen();
      }

      return computeNotBiggerDimension(super.getPreferredSize().getSize(), p);
    }
  public static Point getRelLocation(Component c) {
    if (c == null || !c.isShowing()) {
      return new Point(0, 0);
    }

    Container parent = getRootContainer(c);
    if ((parent != null) && parent.isShowing()) {
      Point p1 = c.getLocationOnScreen();
      Point p2 = parent.getLocationOnScreen();
      return new Point(p1.x - p2.x, p1.y - p2.y);
    }

    return new Point(0, 0);
  }
  protected void customizePopup(BasicComboPopup popup) {
    scrollPane = getScrollPane(popup);

    if (popupWider) popupWider(popup);

    checkHorizontalScrollBar(popup);

    //  For some reason in JDK7 the popup will not display at its preferred
    //  width unless its location has been changed from its default
    //  (ie. for normal "pop down" shift the popup and reset)

    Component comboBox = popup.getInvoker();
    Point location = comboBox.getLocationOnScreen();

    if (popupAbove) {
      int height = popup.getPreferredSize().height;
      popup.setLocation(location.x, location.y - height);
    } else {
      int height = comboBox.getPreferredSize().height;
      popup.setLocation(location.x, location.y + height - 1);
      popup.setLocation(location.x, location.y + height);
    }
  }