javax.swing.JComponent.getLocationOnScreen()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中javax.swing.JComponent.getLocationOnScreen()方法的一些代码示例,展示了JComponent.getLocationOnScreen()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getLocationOnScreen()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getLocationOnScreen

JComponent.getLocationOnScreen介绍

暂无

代码示例

代码示例来源:origin: JetBrains/ideavim

@Nullable
 private static Rectangle getEditorWindowRectangle(@NotNull EditorWindow window) {
  final EditorWithProviderComposite editor = window.getSelectedEditor();
  if (editor != null) {
   final Point point = editor.getComponent().getLocationOnScreen();
   final Dimension dimension = editor.getComponent().getSize();
   return new Rectangle(point, dimension);
  }
  return null;
 }
}

代码示例来源:origin: sdedit/sdedit

private Point screenLocation(MouseEvent e) {
  Point root = view.getLocationOnScreen();
  Point mouse = e.getPoint();
  if (rect != null && !rect.contains(mouse)) {
    return null;
  }
  Point screenPoint = new Point(root.x + mouse.x, root.y + mouse.y);
  return screenPoint;
}

代码示例来源:origin: com.samskivert/samskivert

public void actionPerformed (ActionEvent x)
  {
    // bail if we're behind the times
    if (_scrollComp == null) {
      return;
    }
    // translate the scrollpoint into a point in the scroll component's
    // coordinates
    Point p = _scrollComp.getLocationOnScreen();
    // and tell the scrolling component to scroll that bit on screen
    _scrollComp.scrollRectToVisible(new Rectangle(
      _scrollPoint.x - p.x, _scrollPoint.y - p.y, 1, 1));
  }
});

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

private Point convertPoint(JComponent s, int x, int y, Component f) {
 // return SwingUtilities.convertPoint(s,x,y,top);
 if ((f == null) || !f.isShowing()) return null;
 Point p = s.getLocationOnScreen();
 Point q = f.getLocationOnScreen();
 p.x += x - q.x;
 p.y += y - q.y;
 return p;
}

代码示例来源:origin: otros-systems/otroslogviewer

public static void centerOnComponet(Window target, JComponent parent) {
 Dimension targetSize = target.getSize();
 Point location = parent.getLocationOnScreen();
 Dimension sourceSize = parent.getSize();
 Point sourceCenter = new Point(location.x + sourceSize.width / 2, location.y + sourceSize.height / 2);
 Point frameLocation = new Point(sourceCenter.x - targetSize.width / 2, sourceCenter.y - targetSize.height / 2);
 target.setLocation(frameLocation);
}

代码示例来源:origin: org.gephi/ui-components

public void showTooltip(JComponent component) {
  if (component == null || !component.isShowing()) {
    return;
  }
  showTooltip(component, component.getLocationOnScreen());
}

代码示例来源:origin: com.samskivert/samskivert

/**
 * Find the rectangular area that is visible in screen coordinates
 * for the given component.
 */
protected Rectangle getRectOnScreen (JComponent comp)
{
  Rectangle r = comp.getVisibleRect();
  Point p = comp.getLocationOnScreen();
  r.translate(p.x, p.y);
  return r;
}

代码示例来源:origin: com.cedarsoft.commons.swing/common

@UiThread
public static void showPopupOver(@Nonnull JidePopup popup, @Nonnull JComponent owner) {
 Point locationOnScreen = owner.getLocationOnScreen();
 popup.setOwner(owner);
 showPopupOnScreen(popup, locationOnScreen.x, locationOnScreen.y);
}

代码示例来源:origin: stackoverflow.com

public static Point getToolTipLocation(JComponent component)
{
 Point point = component.getLocationOnScreen();
 int componentHeight = component.getHeight();
 int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
 Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(component.getGraphicsConfiguration());
 int taskBarSize = scnMax.bottom;

 FontMetrics metrics = component.getFontMetrics(component.getFont());
 int height = metrics.getHeight();
 int lines = 1;

 //Tool tip location shifted to up if screen does not have space in the bottom.
 if (point.y + componentHeight + taskBarSize + (height * lines) > screenHeight)
 {
  int xPos = component.getWidth() / 2;
  return new Point(xPos, -((height * lines) + 25));
 }
 return null;
}

代码示例来源:origin: datacleaner/DataCleaner

@Override
public void mouseEntered(final MouseEvent e) {
  if (popupCallback != null && !popupCallback.onBeforeShow()) {
    return;
  } else if (component.isEnabled()) {
    final Point locationOnScreen = component.getLocationOnScreen();
    final int x = locationOnScreen.x + 15;
    if (_position == Position.BOTTOM) {
      DCPopupBubble.this.setLocationOnScreen(x, locationOnScreen.y + component.getHeight());
    } else {
      DCPopupBubble.this.setLocationOnScreen(x, locationOnScreen.y - 81);
    }
    DCPopupBubble.this.show();
  }
}

代码示例来源:origin: com.google.code.validationframework/validationframework-swing

private void followOwner() {
    if (owner.isVisible() && owner.isShowing()) {
      try {
        final Point screenLocation = owner.getLocationOnScreen();
        final Point relativeSlaveLocation = anchorLink.getRelativeSlaveLocation(owner.getSize(),
            ToolTipDialog.this.getSize());
        setLocation(screenLocation.x + relativeSlaveLocation.x, screenLocation.y + relativeSlaveLocation.y);
      } catch (IllegalComponentStateException e) {
        LOGGER.error("Failed getting location of component: " + owner, e);
      }
    }
  }
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

private void updateForBirdViewPoint (Point birdViewPoint) {
  JComponent view = scene.getView ();
  if (view.isShowing ()  &&  isShowing ()) {
    Point viewOrigin = view.getLocationOnScreen ();
    Point birdViewOrigin = getLocationOnScreen ();
    Dimension size = getSize ();
    updateForViewPoint (new Point (birdViewPoint.x + birdViewOrigin.x - viewOrigin.x, birdViewPoint.y + birdViewOrigin.y - viewOrigin.y));
  } else
    updateForViewPoint (null);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

private void updateForBirdViewPoint (Point birdViewPoint) {
  JComponent view = scene.getView ();
  if (view.isShowing ()  &&  isShowing ()) {
    Point viewOrigin = view.getLocationOnScreen ();
    Point birdViewOrigin = getLocationOnScreen ();
    Dimension size = getSize ();
    updateForViewPoint (new Point (birdViewPoint.x + birdViewOrigin.x - viewOrigin.x, birdViewPoint.y + birdViewOrigin.y - viewOrigin.y));
  } else
    updateForViewPoint (null);
}

代码示例来源:origin: com.google.code.validationframework/validationframework-swing

/**
   * Updates the location of the window based on the location of the owner component.
   */
  private void followOwner() {
    if (owner.isVisible() && owner.isShowing()) {
      try {
        Point screenLocation = owner.getLocationOnScreen();
        Point relativeSlaveLocation = anchorLink.getRelativeSlaveLocation(owner.getSize(),
            TransparentToolTipDialog.this.getSize());
        setLocation(screenLocation.x + relativeSlaveLocation.x, screenLocation.y + relativeSlaveLocation.y);
      } catch (IllegalComponentStateException e) {
        LOGGER.error("Failed getting location of component: " + owner, e);
      }
    }
  }
}

代码示例来源:origin: org.tentackle/tentackle-swing

/**
 * Shows an error popup for a given component and message.<br>
 * Any currently displayed error popup will be hidden first.
 * There is only one error popup displayed at a time.
 * The method must be invoked from within the event dispatch thread.
 *
 * @param formComponent the component
 * @param message the message, null to hide
 * @throws IllegalStateException if not invoked from within the dispatch thread
 */
public void showErrorPopup(FormComponent formComponent, String message) {
 hideErrorPopup();
 if (message != null && !message.isEmpty() &&
   formComponent instanceof JComponent && ((JComponent)formComponent).isShowing()) {
  JComponent comp = (JComponent) formComponent;
  ErrorToolTip toolTip = new ErrorToolTip(comp, message);
  Point loc = comp.getLocationOnScreen();
  errorPopup = PopupFactory.getSharedInstance().getPopup(
      comp, toolTip, loc.x + (comp.getWidth() >> 1), loc.y + comp.getHeight() + 2);
  popupComponent = comp;
  popupComponent.addComponentListener(popupComponentListener);
  popupComponent.addHierarchyListener(popupHierarchyListener);
  errorPopup.show();
 }
}

代码示例来源:origin: in.jlibs/org-netbeans-api-visual

private void updateForViewPoint (Point viewPoint) {
  JComponent view = scene.getView ();
  if (! shown  ||  viewPoint == null  ||  ! view.getVisibleRect ().contains (viewPoint)) {
    scenePoint = null;
    setVisible (false);
    dispose ();
    return;
  }
  scenePoint = scene.convertViewToScene (viewPoint);
  Point viewOrigin = view.getLocationOnScreen ();
  Dimension size = getSize ();
  setBounds (viewOrigin.x + viewPoint.x - size.width / 2, viewOrigin.y + viewPoint.y - size.height / 2, size.width, size.height);
  setVisible (true);
  birdView.repaint();
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

private Component getTopLevelAncestor(JComponent s, int x, int y) {
 // return s.getTopLevelAncestor();
 Component r = s.getTopLevelAncestor();
 Point p = SwingUtilities.convertPoint(s, x, y, r);
 Rectangle b = r.getBounds();
 b.x = b.y = 0;
 if (b.contains(p)) {
  if (r instanceof Frame) ((Frame) r).toFront();
  // System.err.println("TOP="+r.getClass());
  return r;
 }
 p = s.getLocationOnScreen();
 p.x += x;
 p.y += y;
 if (windows_ == null) windows_ = DndLib.getAllWindows();
 if (windows_ != null) for (int i = 0; i < windows_.length; i++)
  if (windows_[i].isShowing()) {
   Point q = windows_[i].getLocationOnScreen();
   b = windows_[i].getBounds();
   b.x = q.x;
   b.y = q.y;
   if (b.contains(p)) {
    windows_[i].toFront();
    return windows_[i];
   }
  }
 return null;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-screen

bounds.height += insets.top + insets.bottom;
editorView.setPreferredSize(bounds.getSize());
Point relatedViewLocationOnScreen = relatedView.getLocationOnScreen();
bounds.translate(relatedViewLocationOnScreen.x, relatedViewLocationOnScreen.y);
PopupUtil.showPopup(editorView, NbBundle.getMessage (TopPanel.class, "TITLE_EditorMenu"), bounds.x, bounds.y, true); // NOI18N

代码示例来源:origin: org.netbeans.api/org-netbeans-api-visual

private void updateForViewPoint (Point viewPoint) {
  JComponent view = scene.getView ();
  if (! shown  ||  viewPoint == null  ||  ! view.getVisibleRect ().contains (viewPoint)) {
    scenePoint = null;
    setVisible (false);
    dispose ();
    return;
  }
  scenePoint = scene.convertViewToScene (viewPoint);
  Point viewOrigin = view.getLocationOnScreen ();
  Dimension size = getSize ();
  setBounds (viewOrigin.x + viewPoint.x - size.width / 2, viewOrigin.y + viewPoint.y - size.height / 2, size.width, size.height);
  setVisible (true);
  birdView.repaint();
}

代码示例来源:origin: com.github.lgooddatepicker/LGoodDatePicker

popupRectangle.y = verticalFlipReference.getLocationOnScreen().y - popupHeight
    - verticalFlipDistance;

相关文章

JComponent类方法