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

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

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

Rectangle.setBounds介绍

[英]Sets the bounding Rectangle of this Rectangle to the specified x, y, width, and height.

This method is included for completeness, to parallel the setBounds method of Component.
[中]将此Rectangle的边界Rectangle设置为指定的xywidthheight
为了完整起见,包含此方法,以与ComponentsetBounds方法并行。

代码示例

代码示例来源:origin: groovy/groovy-core

public void paint(Graphics g) {
  if (isVisible()) {
    try {
      JTextComponent component = getComponent();
      Rectangle r = component.getUI().modelToView(component, getDot());
      Color c = g.getColor();
      g.setColor(component.getBackground());
      g.setXORMode(component.getCaretColor());
      r.setBounds(r.x, r.y,
          g.getFontMetrics().charWidth('w'),
          g.getFontMetrics().getHeight());
      g.fillRect(r.x, r.y, r.width, r.height);
      g.setPaintMode();
      g.setColor(c);
    } catch (BadLocationException e) {
      e.printStackTrace();
    }
  }
}

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

private Rectangle getParentBounds(final Widget widget)
  {
    if (!client.isClientThread())
    {
      return parentBounds;
    }

    if (widget == null || widget.isHidden())
    {
      parentBounds.setBounds(new Rectangle());
      return parentBounds;
    }

    final Widget parent = widget.getParent();
    final Rectangle bounds;

    if (parent == null)
    {
      bounds = new Rectangle(client.getRealDimensions());
    }
    else
    {
      bounds = new Rectangle(parent.getCanvasLocation().getX(), parent.getCanvasLocation().getY(), parent.getWidth(), parent.getHeight());
    }

    parentBounds.setBounds(bounds);
    return bounds;
  }
}

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

private Collection<WidgetItem> getShopItems(Client client)
  {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget shop = client.getWidget(WidgetInfo.SHOP_ITEMS_CONTAINER);
    if (shop != null && !shop.isHidden())
    {
      Widget[] children = shop.getDynamicChildren();
      for (int i = 1; i < children.length; i++)
      {
        Widget child = children[i];
        // set bounds to same size as default inventory
        Rectangle bounds = child.getBounds();
        bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
        widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i - 1, bounds));
      }
    }
    return widgetItems;
  }
}

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

private Collection<WidgetItem> getEquippedItems(Client client)
  {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT);
    if (equipment != null && !equipment.isHidden())
    {
      if (slots.isEmpty())
      {
        slots.addAll(Arrays.asList(ALL_EQUIPMENT_WIDGET_INFOS));
      }
      for (WidgetInfo slot : slots)
      {
        Widget parentWidget = client.getWidget(slot);
        Widget itemWidget = parentWidget.getChild(1);
        // Check if background icon is hidden. if hidden, item is equipped.
        boolean equipped = parentWidget.getChild(2).isSelfHidden();
        // set bounds to same size as default inventory
        Rectangle bounds = itemWidget.getBounds();
        bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
        // Index is set to 0 because there is no set in stone order of equipment slots
        widgetItems.add(new WidgetItem(equipped ? itemWidget.getItemId() : -1, itemWidget.getItemQuantity(), 0, bounds));
      }
    }
    return widgetItems;
  }
}

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

bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i, bounds));

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

/**
 * Paint UI related overlays to target graphics
 * @param graphics target graphics
 */
public void paintOverlays(final Graphics2D graphics)
{
  if (!(client instanceof Client) || withTitleBar)
  {
    return;
  }
  final Client client = (Client) this.client;
  final int x = client.getRealDimensions().width - sidebarOpenIcon.getWidth() - 5;
  // Offset sidebar button if resizable mode logout is visible
  final Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_LOGOUT_BUTTON);
  final int y = logoutButton != null && !logoutButton.isHidden() && logoutButton.getParent() != null
    ? logoutButton.getHeight() + logoutButton.getRelativeY()
    : 5;
  final BufferedImage image = sidebarOpen ? sidebarClosedIcon : sidebarOpenIcon;
  final Rectangle sidebarButtonRange = new Rectangle(x - 15, 0, image.getWidth() + 25, client.getRealDimensions().height);
  final Point mousePosition = new Point(
    client.getMouseCanvasPosition().getX() + client.getViewportXOffset(),
    client.getMouseCanvasPosition().getY() + client.getViewportYOffset());
  if (sidebarButtonRange.contains(mousePosition.getX(), mousePosition.getY()))
  {
    graphics.drawImage(image, x, y, null);
  }
  // Update button dimensions
  sidebarButtonPosition.setBounds(x, y, image.getWidth(), image.getHeight());
}

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

private Collection<WidgetItem> getBankItems(Client client)
  {
    Collection<WidgetItem> widgetItems = new ArrayList<>();
    Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
    if (bank != null && !bank.isHidden())
    {
      Widget[] children = bank.getDynamicChildren();
      for (int i = 0; i < children.length; i++)
      {
        Widget child = children[i];
        if (child.getItemId() == ITEM_EMPTY || child.isSelfHidden())
        {
          continue;
        }
        // set bounds to same size as default inventory
        Rectangle bounds = child.getBounds();
        bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
        // Index is set to 0 because the widget's index does not correlate to the order in the bank
        widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), 0, bounds));
      }
    }
    return widgetItems;
  }
}

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

public void setSourceRegion(final Rectangle pSourceRegion) {
  if (pSourceRegion == null) {
    sourceRegion = null;
  }
  else {
    if (sourceRegion == null) {
      sourceRegion = new Rectangle(pSourceRegion);
    }
    else {
      sourceRegion.setBounds(pSourceRegion);
    }
  }
}

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

public void setSourceRegion(final Rectangle pSourceRegion) {
  if (pSourceRegion == null) {
    sourceRegion = null;
  }
  else {
    if (sourceRegion == null) {
      sourceRegion = new Rectangle(pSourceRegion);
    }
    else {
      sourceRegion.setBounds(pSourceRegion);
    }
  }
}

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

public @Override void setBounds(int x, int y, int w, int h) {
  if (swingRendering) {
    super.setBounds(x, y, w, h);
  }
  bounds.setBounds(x, y, w, h);
}

代码示例来源:origin: ron190/jsql-injection

public void autoScrollTest(Point pt) {
  Rectangle r = this.getTabAreaBounds();
  if (isTopBottomTabPlacement(this.getTabPlacement())) {
    RECT_BACKWARD.setBounds(r.x, r.y, SCROLL_SIZE, r.height);
    RECT_FORWARD.setBounds(r.x + r.width - SCROLL_SIZE - BUTTON_SIZE, r.y, SCROLL_SIZE + BUTTON_SIZE, r.height);
  } else { // if (tabPlacement == LEFT || tabPlacement == RIGHT) {
    RECT_BACKWARD.setBounds(r.x, r.y, r.width, SCROLL_SIZE);
    RECT_FORWARD.setBounds(r.x, r.y + r.height - SCROLL_SIZE - BUTTON_SIZE, r.width, SCROLL_SIZE + BUTTON_SIZE);
  }
  if (RECT_BACKWARD.contains(pt)) {
    this.clickArrowButton("scrollTabsBackwardAction");
  } else if (RECT_FORWARD.contains(pt)) {
    this.clickArrowButton("scrollTabsForwardAction");
  }
}

代码示例来源:origin: ron190/jsql-injection

public Optional<Rectangle> getDropLineRect() {
  int index = Optional.ofNullable(this.getDropLocation())
    .filter(DropLocation::isDroppable)
    .map(DropLocation::getIndex)
    .orElse(-1);
  if (index < 0) {
    RECT_LINE.setBounds(0, 0, 0, 0);
    return Optional.empty();
  }
  int a = Math.min(index, 1); // index == 0 ? 0 : 1;
  Rectangle r = this.getBoundsAt(a * (index - 1));
  if (isTopBottomTabPlacement(this.getTabPlacement())) {
    RECT_LINE.setBounds(r.x - LINE_WIDTH / 2 + r.width * a, r.y, LINE_WIDTH, r.height);
  } else {
    RECT_LINE.setBounds(r.x, r.y - LINE_WIDTH / 2 + r.height * a, r.width, LINE_WIDTH);
  }
  return Optional.of(RECT_LINE);
}

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

canvasBounds.setBounds(p.getX(), p.getY() + BUTTON_HEIGHT, bounds.width, maxTabs * TAB_HEIGHT + maxTabs * MARGIN);

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

/**
 * Disposes of the focusable tip currently displayed, if any.
 */
public void possiblyDisposeOfTipWindow() {
  if (tipWindow != null) {
    tipWindow.dispose();
    tipWindow = null;
    textAreaListener.uninstall();
    tipVisibleBounds.setBounds(-1, -1, 0, 0);
    lastText = null;
    textArea.requestFocus();
  }
}

代码示例来源:origin: ron190/jsql-injection

@Override 
public void mouseDragged(MouseEvent e) {
  Point tabPt = e.getPoint(); // e.getDragOrigin();
  if (Objects.nonNull(this.startPt) && this.startPt.distance(tabPt) > this.gestureMotionThreshold) {
    DnDTabbedPane src = (DnDTabbedPane) e.getComponent();
    TransferHandler th = src.getTransferHandler();
    DnDTabbedPane.this.dragTabIndex = src.indexAtLocation(tabPt.x, tabPt.y);
    th.exportAsDrag(src, e, TransferHandler.MOVE);
    RECT_LINE.setBounds(0, 0, 0, 0);
    src.getRootPane().getGlassPane().setVisible(true);
    src.setDropLocation(new DropLocation(tabPt, -1), null, true);
    this.startPt = null;
  }
}

代码示例来源: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: geotools/geotools

sourceRegion.setBounds(new Rectangle(0, 0, Integer.MIN_VALUE, Integer.MIN_VALUE));

代码示例来源:origin: ron190/jsql-injection

RECT.setBounds(this.x, this.y + height - SHADOW_SIZE, width, SHADOW_SIZE);
BufferedImage hShadowBg = robot.createScreenCapture(RECT);
RECT.setBounds(this.x + width - SHADOW_SIZE, this.y, SHADOW_SIZE,
    height - SHADOW_SIZE);
BufferedImage vShadowBg = robot.createScreenCapture(RECT);

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

public void getRectangle(Rectangle r) {
  synchronized(tempRect) {
    r.setBounds(tempRect);
  }
}

代码示例来源:origin: danfickle/openhtmltopdf

private static void transformBounds(Rectangle bounds, AffineTransform transform) {
  if (transform != null) {
    FourPoint corners = getCornersFromTransformedBounds(bounds, transform);
    double minX = getMinX(corners);
    double minY = getMinY(corners);
    double maxX = getMaxX(corners);
    double maxY = getMaxY(corners);
    
    bounds.setBounds((int) minX, (int) minY, (int) (maxX - minX), (int) (maxY - minY));
  }
}

相关文章