java.awt.Rectangle.setLocation()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(132)

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

Rectangle.setLocation介绍

[英]Moves this Rectangle to the specified location.

This method is included for completeness, to parallel the setLocation method of Component.
[中]将此Rectangle移动到指定位置。
包含此方法是为了完整性,与ComponentsetLocation方法并行。

代码示例

代码示例来源:origin: looly/hutool

/**
 * 修正矩形框位置,如果{@link Img#setPositionFromCentre(boolean)} 设为{@code true},则坐标修正为基于图形中心,否则基于左上角
 * 
 * @param rectangle 矩形
 * @param baseWidth 参考宽
 * @param baseHeight 参考高
 * @return 修正后的{@link Rectangle}
 * @since 4.1.15
 */
private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) {
  if (this.positionBaseCentre) {
    // 修正图片位置从背景的中心计算
    rectangle.setLocation(//
        rectangle.x + (int) (Math.abs(baseWidth - rectangle.width) / 2), //
        rectangle.y + (int) (Math.abs(baseHeight - rectangle.height) / 2)//
    );
  }
  return rectangle;
}

代码示例来源:origin: looly/hutool

/**
 * 修正矩形框位置,如果{@link Img#setPositionFromCentre(boolean)} 设为{@code true},则坐标修正为基于图形中心,否则基于左上角
 * 
 * @param rectangle 矩形
 * @param baseWidth 参考宽
 * @param baseHeight 参考高
 * @return 修正后的{@link Rectangle}
 * @since 4.1.15
 */
private Rectangle fixRectangle(Rectangle rectangle, int baseWidth, int baseHeight) {
  if (this.positionBaseCentre) {
    // 修正图片位置从背景的中心计算
    rectangle.setLocation(//
        rectangle.x + (int) (Math.abs(baseWidth - rectangle.width) / 2), //
        rectangle.y + (int) (Math.abs(baseHeight - rectangle.height) / 2)//
    );
  }
  return rectangle;
}

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

outsideStroke.setLocation(rectangle.x, rectangle.y);
outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET / 2);
graphics.setColor(outsideStrokeColor);
insideStroke.setLocation(rectangle.x + BORDER_OFFSET / 2, rectangle.y + BORDER_OFFSET / 2);
insideStroke.setSize(rectangle.width - BORDER_OFFSET - BORDER_OFFSET / 2,
    rectangle.height - BORDER_OFFSET - BORDER_OFFSET / 2);

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

@Override
public Rectangle getBounds()
{
  final Rectangle bounds = super.getBounds();
  final Rectangle parent = getParentBounds(client.getWidget(widgetInfo));
  if (parent.isEmpty())
  {
    return bounds;
  }
  int x = bounds.x;
  int y = bounds.y;
  x = Math.max(parent.x, x);
  y = Math.max(parent.y, y);
  x = Math.min((int)parent.getMaxX() - bounds.width, x);
  y = Math.min((int)parent.getMaxY() - bounds.height, y);
  bounds.setLocation(x, y);
  return bounds;
}

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

private void positionPanel() {
 if (parent == null) return;
 Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, parent);
 int height = (int)getPreferredSize().getHeight();
 if (scroll != null) {
  Rectangle bounds = scroll.getBounds();
  bounds.translate(0, scroll.getHeight() - height);
  bounds.height = height;
  Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), oldGlass);
  bounds.setLocation(pos);
  setBounds(bounds);
  repaint();
 }
}

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

@Override
public Dimension render(Graphics2D graphics)
{
  final Widget widget = client.getWidget(widgetInfo);
  final Rectangle bounds = super.getBounds();
  final Rectangle parent = getParentBounds(widget);
  if (parent.isEmpty())
  {
    return null;
  }
  int x = bounds.x;
  int y = bounds.y;
  x = Math.max(parent.x, x);
  y = Math.max(parent.y, y);
  x = Math.min((int)parent.getMaxX() - bounds.width, x);
  y = Math.min((int)parent.getMaxY() - bounds.height, y);
  bounds.setLocation(x, y);
  widget.setOriginalX(0);
  widget.setOriginalY(0);
  widget.setRelativeX(bounds.x - parent.x);
  widget.setRelativeY(bounds.y - parent.y);
  return new Dimension(widget.getWidth(), widget.getHeight());
}

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

public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) {
   if (!(table.getParent() instanceof JViewport)) {
     return;
   }
   JViewport viewport = (JViewport)table.getParent();
   // This rectangle is relative to the table where the
   // northwest corner of cell (0,0) is always (0,0).
   Rectangle rect = table.getCellRect(rowIndex, vColIndex, true);
   // The location of the viewport relative to the table
   Point pt = viewport.getViewPosition();
   // Translate the cell location so that it is relative
   // to the view, assuming the northwest corner of the
   // view is (0,0)
   rect.setLocation(rect.x-pt.x, rect.y-pt.y);
   table.scrollRectToVisible(rect);
   // Scroll the area into view
   //viewport.scrollRectToVisible(rect);
 }

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

final Insets windowInsets = window.getInsets();
pos.translate(windowInsets.left, windowInsets.top);
bounds.setLocation(pos);
setBounds(bounds);

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

final Point mousePosition = new Point(mouseCanvasPosition.getX(), mouseCanvasPosition.getY() + OFFSET);
final Rectangle bounds = new Rectangle(getBounds());
bounds.setLocation(mousePosition);

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

private void positionPanel() {
 final JComponent contentComponent = myEditor.getContentComponent();
 Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent);
 setSize(scroll.getSize());
 myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight();
 int count = countLines(myText.getText());
 int visLines = getSize().height / myLineHeight - 1;
 int lines = Math.min(count, visLines);
 setSize(getSize().width, lines * myLineHeight + myLabel.getPreferredSize().height +
              getBorder().getBorderInsets(this).top * 2);
 int height = getSize().height;
 Rectangle bounds = scroll.getBounds();
 bounds.translate(0, scroll.getHeight() - height);
 bounds.height = height;
 Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(),
                     SwingUtilities.getRootPane(contentComponent).getGlassPane());
 bounds.setLocation(pos);
 setBounds(bounds);
 myScrollPane.getVerticalScrollBar().setValue(0);
 if (!Options.getInstance().isSet("more")) {
  // FIX
  scrollOffset(100000);
 }
 else {
  scrollOffset(0);
 }
}

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

final Rectangle canvasBounds = client.getCanvas().getBounds();
canvasBounds.setLocation(0, 0);
final Area canvasViewArea = getWorldMapClipArea(canvasBounds);
Area currentClip = null;

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

bounds.setLocation(MARGIN, TAB_HEIGHT + MARGIN);

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Reads the rectangle location and size from an 8-byte rectangle stream.
 *
 * @param pStream the stream to read from
 * @param pDestRect the rectangle to read into
 *
 * @throws NullPointerException if {@code pDestRect} is {@code null}
 * @throws IOException if an I/O error occurs while reading the image.
 */
private void readRectangle(DataInput pStream, Rectangle pDestRect) throws IOException {
  int y = pStream.readUnsignedShort();
  int x = pStream.readUnsignedShort();
  int h = pStream.readUnsignedShort();
  int w = pStream.readUnsignedShort();
  pDestRect.setLocation(getXPtCoord(x), getYPtCoord(y));
  pDestRect.setSize(getXPtCoord(w - x), getYPtCoord(h - y));
}

代码示例来源:origin: RaiMan/SikuliX2

public void setActualLocation(int x, int y) {
 int paintX = x;
 int paintY = y;
 actualBounds.setLocation(x, y);
 if (hasShadow()) {
  paintX -= (shadowSize - shadowOffset);
  paintY -= (shadowSize - shadowOffset);
 }
 super.setLocation(paintX, paintY);
 updateAllFollowers();
}

代码示例来源:origin: magefree/mage

public int showTokens() {
  jLayeredPane.removeAll();
  List<Token> tokens = getTokens(currentPage, currentSet);
  if (tokens != null && tokens.size() > 0) {
    int size = tokens.size();
    Rectangle rectangle = new Rectangle();
    rectangle.translate(OFFSET_X, OFFSET_Y);
    for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) {
      Token token = tokens.get(i);
      addToken(token, bigCard, null, rectangle);
      rectangle = CardPosition.translatePosition(i, rectangle, conf);
    }
    // calculate the x offset of the second (right) page
    int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
        - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
    rectangle.setLocation(second_page_x, OFFSET_Y);
    for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
      Token token = tokens.get(i);
      addToken(token, bigCard, null, rectangle);
      rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf);
    }
    jLayeredPane.repaint();
    return tokens.size();
  }
  return 0;
}

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

public static void centerOnScreen(Window w, Window parent) {
  Rectangle r = new Rectangle();
  if (parent == null) {
    r.setSize(Toolkit.getDefaultToolkit().getScreenSize());
  } else {
    r.setLocation(parent.getLocation());
    r.setSize(parent.getSize());
  }
  // Determine the new location of the alert
  int x = r.x + (r.width - w.getWidth()) / 2;
  int y = r.y + (r.height - w.getHeight()) / 2;
  // Move the alert
  w.setLocation(x, y);
}

代码示例来源:origin: bobbylight/RSyntaxTextArea

/**
 * Compute the bounds in which the user can move the mouse without the
 * tip window disappearing.
 */
private void computeTipVisibleBounds() {
  // Compute area that the mouse can move in without hiding the
  // tip window. Note that Java 1.4 can only detect mouse events
  // in Java windows, not globally.
  Rectangle r = tipWindow.getBounds();
  Point p = r.getLocation();
  SwingUtilities.convertPointFromScreen(p, textArea);
  r.setLocation(p);
  tipVisibleBounds.setBounds(r.x,r.y-15, r.width,r.height+15*2);
}

代码示例来源:origin: magefree/mage

public void showCards() {
  jLayeredPane.removeAll();
  // stats info
  updateCardStats(currentSet, true);
  List<CardInfo> cards = getCards(currentPage, currentSet);
  int size = cards.size();
  Rectangle rectangle = new Rectangle();
  rectangle.translate(OFFSET_X, OFFSET_Y);
  for (int i = 0; i < min(conf.CARDS_PER_PAGE / 2, size); i++) {
    Card card = cards.get(i).getMockCard();
    addCard(new CardView(card), bigCard, null, rectangle);
    rectangle = CardPosition.translatePosition(i, rectangle, conf);
  }
  // calculate the x offset of the second (right) page
  int second_page_x = (conf.WIDTH - 2 * LEFT_RIGHT_PAGES_WIDTH)
      - (cardDimensions.frameWidth + CardPosition.GAP_X) * conf.CARD_COLUMNS + CardPosition.GAP_X - OFFSET_X;
  rectangle.setLocation(second_page_x, OFFSET_Y);
  for (int i = conf.CARDS_PER_PAGE / 2; i < min(conf.CARDS_PER_PAGE, size); i++) {
    Card card = cards.get(i).getMockCard();
    addCard(new CardView(card), bigCard, null, rectangle);
    rectangle = CardPosition.translatePosition(i - conf.CARDS_PER_PAGE / 2, rectangle, conf);
  }
  jLayeredPane.repaint();
}

代码示例来源:origin: magefree/mage

rectangleBaseCard.setLocation(point);

代码示例来源:origin: haraldk/TwelveMonkeys

sourceRegion.setLocation(
    (int) Math.round((IMAGE_DIMENSION_PNG.width - sourceRegion.getWidth()) / 2.0),
    (int) Math.round((IMAGE_DIMENSION_PNG.height - sourceRegion.getHeight()) / 2.0)

相关文章