Tabnine Logo
Rectangle
Code IndexAdd Tabnine to your IDE (free)

How to use
Rectangle
in
java.awt

Best Java code snippets using java.awt.Rectangle (Showing top 20 results out of 10,548)

Refine searchRefine arrow

  • Graphics2D
  • Graphics
  • Container
  • JFrame
  • Window
  • Component
  • Dimension
origin: runelite/runelite

private void drawTooltip(Graphics2D graphics, WorldMapPoint worldPoint)
{
  String tooltip = worldPoint.getTooltip();
  Point drawPoint = mapWorldPointToGraphicsPoint(worldPoint.getWorldPoint());
  if (tooltip == null || tooltip.length() <= 0 || drawPoint == null)
  {
    return;
  }
  drawPoint = new Point(drawPoint.getX() + TOOLTIP_OFFSET_WIDTH, drawPoint.getY() + TOOLTIP_OFFSET_HEIGHT);
  graphics.setClip(client.getCanvas().getBounds());
  graphics.setColor(JagexColors.TOOLTIP_BACKGROUND);
  graphics.setFont(FontManager.getRunescapeFont());
  FontMetrics fm = graphics.getFontMetrics();
  int width = fm.stringWidth(tooltip);
  int height = fm.getHeight();
  Rectangle tooltipRect = new Rectangle(drawPoint.getX() - TOOLTIP_PADDING_WIDTH, drawPoint.getY() - TOOLTIP_PADDING_HEIGHT, width + TOOLTIP_PADDING_WIDTH * 2, height + TOOLTIP_PADDING_HEIGHT * 2);
  graphics.fillRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight());
  graphics.setColor(JagexColors.TOOLTIP_BORDER);
  graphics.drawRect((int) tooltipRect.getX(), (int) tooltipRect.getY(), (int) tooltipRect.getWidth(), (int) tooltipRect.getHeight());
  graphics.setColor(JagexColors.TOOLTIP_TEXT);
  graphics.drawString(tooltip, drawPoint.getX(), drawPoint.getY() + height);
}
origin: sarxos/webcam-capture

/**
 * Return true if point identified by x and y coordinates is in one of the do-not-engage zones.
 * Return false otherwise.
 *
 * @param x the x coordinate of a point
 * @param y the y coordinate of a point
 * @return True if point is in one of do-not-engage zones, false otherwise
 */
private boolean isInDoNotEngageZone(final int x, final int y) {
  for (final Rectangle zone : doNotEnganeZones) {
    if (zone.contains(x, y)) {
      return true;
    }
  }
  return false;
}
origin: runelite/runelite

@Override
public void setBounds(int x, int y, int width, int height)
{
  if (containedInScreen)
  {
    Rectangle bounds = this.getGraphicsConfiguration().getBounds();
    width = Math.min(width, width - (int)bounds.getX() + x);
    x = Math.max(x, (int)bounds.getX());
    height = Math.min(height, height - (int)bounds.getY() + y);
    y = Math.max(y, (int)bounds.getY());
    width = Math.min(width, (int)(bounds.getX() + bounds.getWidth()) - x);
    height = Math.min(height, (int)(bounds.getY() + bounds.getHeight()) - y);
  }
  super.setBounds(x, y, width, height);
}
origin: runelite/runelite

private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int itemId, Color color)
{
  if (itemId == -1)
  {
    return;
  }
  String text = itemId + "";
  FontMetrics fm = graphics.getFontMetrics();
  Rectangle2D textBounds = fm.getStringBounds(text, graphics);
  int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
  int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2));
  graphics.setColor(Color.BLACK);
  graphics.drawString(text, textX + 1, textY + 1);
  graphics.setColor(color);
  graphics.drawString(text, textX, textY);
}
origin: log4j/log4j

public boolean inCheckBoxHitRegion(MouseEvent e) {
 TreePath path = tree.getPathForLocation(e.getX(),
   e.getY());
 if (path == null) {
  return false;
 }
 CategoryNode node = (CategoryNode) path.getLastPathComponent();
 boolean rv = false;
 if (true) {
  // offset and lastRow DefaultTreeCellEditor
  // protected members
  Rectangle bounds = tree.getRowBounds(lastRow);
  Dimension checkBoxOffset =
    renderer.getCheckBoxOffset();
  bounds.translate(offset + checkBoxOffset.width,
    checkBoxOffset.height);
  rv = bounds.contains(e.getPoint());
 }
 return true;
}
origin: stackoverflow.com

private JFrame frame = new JFrame("sssssssss");
private JButton tip1Null = new JButton(" test button ");
  tip1Null.setFont(new Font("Serif", Font.BOLD, 14));
  tip1Null.setForeground(Color.darkGray);
  tip1Null.setPreferredSize(new Dimension(50, 30));
  tip1Null.addActionListener(new java.awt.event.ActionListener() {
    @Override
  ((Graphics2D) g).setRenderingHint(
    RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g.setColor(color);
  g.drawRoundRect(x, y, width, height, MARGIN, MARGIN);
  GradientPaint gradient1 = new GradientPaint(
    0.0F, (float) c.getHeight() / (float) 2, color1, 0.0F, 0.0F, color2);
  Rectangle rec1 = new Rectangle(0, 0, c.getWidth(), c.getHeight() / 2);
  g2D.setPaint(gradient1);
  g2D.fill(rec1);
  GradientPaint gradient2 = new GradientPaint(
    0.0F, (float) c.getHeight() / (float) 2, color3, 0.0F, c.getHeight(), color4);
  Rectangle rec2 = new Rectangle(0, c.getHeight() / 2, c.getWidth(), c.getHeight());
  paintText(g, b, b.getBounds(), b.getText());
  g.setColor(Color.red.brighter());
  g.fillRect(0, 0, b.getSize().width, b.getSize().height);
origin: stackoverflow.com

private static final int FRAMES = 24;
private final Timer timer = new Timer(20, this);
private final Rectangle rect = new Rectangle();
private BufferedImage background;
private int index;
  super(true);
  this.setOpaque(false);
  this.setPreferredSize(new Dimension(WIDE, HIGH));
  this.addMouseListener(new MouseHandler());
  this.addComponentListener(new ComponentHandler());
  int w = this.getWidth();
  int h = this.getHeight();
  g.drawImage(background, 0, 0, this);
  double theta = 2 * Math.PI * index++ / 64;
  g.setColor(Color.blue);
  rect.setRect(
    (int) (Math.sin(theta) * w / 3 + w / 2 - RADIUS),
    (int) (Math.cos(theta) * h / 3 + h / 2 - RADIUS),
    2 * RADIUS, 2 * RADIUS);
  g.fillOval(rect.x, rect.y, rect.width, rect.height);
  this.repaint();
    add(field);
origin: stackoverflow.com

      repaint();
  addMouseMotionListener(mouseHandler);
  return new Dimension(200, 200);
protected void paintComponent(Graphics g) {
  super.paintComponent(g);
  Graphics2D g2d = (Graphics2D) g.create();
    for (int row = 0; row < rowCount; row++) {
      for (int col = 0; col < columnCount; col++) {
        Rectangle cell = new Rectangle(
            xOffset + (col * cellWidth),
            yOffset + (row * cellHeight),
    g2d.setColor(Color.BLUE);
    g2d.fill(cell);
  g2d.setColor(Color.GRAY);
  for (Rectangle cell : cells) {
    g2d.draw(cell);
origin: stackoverflow.com

public MyCanvas() {
  random = new Random();
  rectangle = new Rectangle(50, 50, 250, 250);
  lastTimeChanged = System.currentTimeMillis();
  setBackground(Color.WHITE);
  g.clipRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
  g.drawImage(buffImg, 0, 0, getWidth(), getHeight(), this);
  Graphics2D g2d = (Graphics2D)g.create();
  g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  g2d.setColor(Color.DARK_GRAY);
  g2d.fillRoundRect(getWidth()/2-100, getHeight()/2-15, 200, 30, 30, 30);
  g2d.setColor(Color.WHITE);
  g2d.drawString("Loading image...", getWidth()/2 - 45, getHeight()/2 + 3 );
  g2d.dispose();
  rectangle.y = rectangle.y + dirY * 10;;
  repaint();
    public void run() {
      final MyCanvas canvas = new MyCanvas();
      JFrame frame = new JFrame();
     frame.setSize(new Dimension(500, 500));
     frame.add(canvas);
     frame.setVisible(true);
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
origin: wildfly/wildfly

public void go() throws Exception {
  if(!no_channel && !use_state)
    channel.connect(cluster_name);
  mainFrame=new JFrame();
  mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  panel=new DrawPanel(use_state);
  panel.setBackground(background_color);
  sub_panel=new JPanel();
  mainFrame.getContentPane().add("Center", panel);
  clear_button=new JButton("Clear");
  clear_button.setFont(default_font);
  clear_button.addActionListener(this);
  leave_button=new JButton("Leave");
  leave_button.setFont(default_font);
  leave_button.addActionListener(this);
  sub_panel.add("South", clear_button);
  sub_panel.add("South", leave_button);
  mainFrame.getContentPane().add("South", sub_panel);
  mainFrame.setBackground(background_color);
  clear_button.setForeground(Color.blue);
  leave_button.setForeground(Color.blue);
  mainFrame.pack();
  mainFrame.setLocation(15, 25);
  mainFrame.setBounds(new Rectangle(250, 250));
  if(!no_channel && use_state) {
    channel.connect(cluster_name, null, state_timeout);
  }
  mainFrame.setVisible(true);
  setTitle();
}
origin: stackoverflow.com

final JFrame frame = new JFrame("Image zoom");
frame.getContentPane().add(zoomPanel);
final Ticker t = new Ticker(zoomPanel);
frame.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent we) {
    t.done();
    frame.dispose();
frame.setLocation(new Point(640, 0));
frame.pack();
frame.setVisible(true);
setSize(new Dimension(400, 400));
setMinimumSize(new Dimension(400, 400));
setPreferredSize(new Dimension(400, 400));
setOpaque(true);
repaint(40 + x * STEP, 45 + y * STEP, 40 + (x * STEP) - 3, 45 + (y * STEP) - 3);
g2.setColor(getBackground());
try {
    Rectangle rect = new Rectangle(p.x - 4, p.y - 4, 8, 8);
    final BufferedImage capture = robot.createScreenCapture(rect);
origin: stackoverflow.com

  JFrame frame = new JFrame("Test");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.setLayout(new BorderLayout());
  frame.add(new TestPane());
  frame.pack();
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
  Area area = new Area(new Rectangle(width, height));
  area.subtract(new Area(new Rectangle(width - (shadowSize * 2), height - (shadowSize * 2))));
  g2d.setClip(clip);
if (!c.isOpaque() && isFillContentArea()) {
  area = new Area(new Rectangle(width - (shadowSize * 2), height - (shadowSize * 2)));
  g2d.setColor(c.getBackground());
  g2d.fill(area);
  BORDER_CACHE.put(c, new CachedBorder(dropShadow, c.getSize()));
g.drawImage(dropShadow, x, y, c);
origin: stackoverflow.com

private Dimension rectSize = new Dimension();
private int zoom = 80;
private BufferedImage capture = null;
  raw = new Robot().createScreenCapture(new Rectangle(
      Toolkit.getDefaultToolkit().getScreenSize()));
  MouseBehavior behavior = new MouseBehavior();
      return new Dimension(500, 500);
      return new Dimension(500, 500);
      super.paintComponent(g);
      Graphics2D g2d = ((Graphics2D) g);
      g2d.drawImage(raw, 0, 0, null);
      if (capture != null) {
        int width2 = (int) (rectSize.width + rectSize.width * (zoom / 500d));
        Image scaledInstance = capture.getScaledInstance(
            width2, height2, Image.SCALE_AREA_AVERAGING);
        g2d.drawImage(scaledInstance, x2, y2, null);
        g2d.drawRect(x2, y2, width2, height2);
      } else {
        g2d.draw(new Rectangle(rectLocale, rectSize));
origin: stackoverflow.com

ta.setFocusable(false);
return ta;
        "Config " +
        i,
        (int) gc[i].getBounds().getWidth() +
        "x" +
        (int) gc[i].getBounds().getHeight() +
        " " +
        gc[i].getColorModel() +
JPanel fontTable = new JPanel(new BorderLayout(3, 1));
fontTable.setFocusable(true);
JPanel fontNameCol = new JPanel(new GridLayout(0, 1, 2, 2));
JPanel fontExampleCol = new JPanel(new GridLayout(0, 1, 2, 2));
fontTable.add(fontNameCol, BorderLayout.WEST);
fontTable.add(fontExampleCol, BorderLayout.CENTER);
for (int ii = 0; ii < fonts.length; ii++) {
  fontNameCol.add(new JLabel(fonts[ii]));
  fontExampleCol.add(getExampleOfFont(fonts[ii]));
origin: stackoverflow.com

JScrollPane screenScroll = new JScrollPane(screenLabel);
screenScroll.setPreferredSize(new Dimension(
    (int)(screen.getWidth()/3),
    (int)(screen.getHeight()/3)));
panel.add(screenScroll, BorderLayout.CENTER);
panel.add(selectionLabel, BorderLayout.SOUTH);
screenLabel.repaint();
screenLabel.addMouseMotionListener(new MouseMotionAdapter() {
  public void mouseDragged(MouseEvent me) {
    Point end = me.getPoint();
    captureRect = new Rectangle(start,
        new Dimension(end.x-start.x, end.y-start.y));
    repaint(screen, screenCopy);
    screenLabel.repaint();
g.dispose();
    getScreenSize();
final BufferedImage screen = robot.createScreenCapture(
    new Rectangle(screenSize));
origin: stackoverflow.com

jpb.setForeground(Color.blue);
jpb.setIndeterminate(true);
this.add(jpb);
private Rectangle r = new Rectangle();
  g2d.setRenderingHint(
    RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
  r = getBox(r);
  g.setColor(progressBar.getForeground());
  g.fillOval(r.x, r.y, r.width, r.height);
JFrame f = new JFrame("ProgressBarUITest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
origin: runelite/runelite

  graphics.setColor(backgroundColor);
  graphics.fill(rectangle);
final Rectangle outsideStroke = new Rectangle();
outsideStroke.setLocation(rectangle.x, rectangle.y);
outsideStroke.setSize(rectangle.width - BORDER_OFFSET / 2, rectangle.height - BORDER_OFFSET / 2);
graphics.setColor(outsideStrokeColor);
graphics.draw(outsideStroke);
final Rectangle insideStroke = new Rectangle();
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);
graphics.setColor(insideStrokeColor);
graphics.draw(insideStroke);
return new Dimension(rectangle.getSize());
origin: stackoverflow.com

Rectangle r = f.getBounds();
int x = (int)r.getX();
int y = (int)r.getY();
int w = (int)r.getWidth();
int h = (int)r.getHeight();
int h = Integer.parseInt(p.getProperty("h"));
Rectangle r = new Rectangle(x,y,w,h);
f.setBounds(r);
final JFrame f = new JFrame("Good Location & Size");
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener( new WindowAdapter() {
  public void windowClosing(WindowEvent we) {
    try {
f.add(ta);
f.pack();
origin: stackoverflow.com

 public static void main(String[] args) {
  Rectangle box = new Rectangle(5, 10, 20, 30);

  // New stuff - Create a program window and set it up.
  JFrame window = new JFrame();

  // Tell Swing to exit the program when the program window is closed.
  window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  // Set the window boundaries to be 300x300 on the screen, and position it 30 pixels from the top and left edges of the monitor.
  window.setBounds(30, 30, 300, 300);

  // Get the content pane of the window, and give it our own custom component.
  window.getContentPane().add(new JComponent() {  // Not a typo - this is some advanced magic called an "anonymous class".
    Rectangle myBox = box;    // Give the component a reference to our box object.
    public void paint(Graphics g) {
      g.drawRect(myBox.x, myBox.y, myBox.width, myBox.height);
    }
  });

  // Make our window appear.
  window.setVisible(true);
}
origin: stackoverflow.com

public GameFrame() {
 super("Game Frame");
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 Squares squares = new Squares();
 getContentPane().add(squares);
 for (int i = 0; i < 15; i++) {
   squares.addSquare(i * 10, i * 10, 100, 100);
 pack();
 setLocationRelativeTo(null);
 setVisible(true);
 Rectangle rect = new Rectangle(x, y, width, height);
 squares.add(rect);
 return new Dimension(PREF_W, PREF_H);
 Graphics2D g2 = (Graphics2D) g;
 for (Rectangle rect : squares) {
   g2.draw(rect);
java.awtRectangle

Javadoc

A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-left point (x, y) in the coordinate space, its width, and its height.

A Rectangle object's width and height are public fields. The constructors that create a Rectangle, and the methods that can modify one, do not prevent setting a negative value for width or height.

A Rectangle whose width or height is negative is considered empty. If the Rectangle is empty, then the isEmpty method returns true. No point can be contained by or inside an empty Rectangle. The values of width and height, however, are still valid. An empty Rectangle still has a location in the coordinate space, and methods that change its size or location remain valid. The behavior of methods that operate on more than one Rectangle is undefined if any of the participating Rectangle objects has a negative width or height. These methods include intersects, intersection, and union.

Most used methods

  • <init>
    Constructs a new Rectangle, initialized to match the values of the specified Rectangle.
  • contains
  • getWidth
  • getHeight
  • intersects
  • getY
  • setBounds
    Sets the bounding Rectangle of this Rectangle to match the specified Rectangle. This method is incl
  • intersection
    Computes the intersection of this Rectangle with the specified Rectangle. Returns a new Rectangle th
  • getX
  • getSize
    Gets the size of this Rectangle, represented by the returned Dimension. This method is included for
  • getLocation
    Returns the location of this Rectangle. This method is included for completeness, to parallel theget
  • equals
    Checks whether two rectangles are equal. The result is true if and only if the argument is notnull a
  • getLocation,
  • equals,
  • isEmpty,
  • setLocation,
  • getMinX,
  • union,
  • getMinY,
  • getMaxY,
  • getMaxX,
  • translate

Popular in Java

  • Finding current android device location
  • compareTo (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • setScale (BigDecimal)
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • JButton (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now