/** * Returns the position and the bounds of the rectangle. These * bounds can be slightly bigger than those returned by * {@link #getFrame} since {@code getBounds2D()} returns the * bounds of the rectangle visible on screen, which can have certain * minimum bounds. */ public Rectangle getBounds() { return drawnShape.getBounds(); }
Rectangle bounds = ball.getBounds(); bounds.y += ballYDelta; if (bounds.y < 0) {
short getRowHeight(Row row, String cellValue, Font font, float cellWidth) { if(cellValue.isEmpty()) return row.getHeight(); // Create Font object with Font attribute (e.g. Font family, Font size, etc) for calculation int style = java.awt.Font.PLAIN; if(font.getBoldweight() == Font.BOLDWEIGHT_BOLD) style = java.awt.Font.BOLD; java.awt.Font currFont = new java.awt.Font(font.getFontName(), style, font.getFontHeight()); double requiredWidth = currFont.getStringBounds(cellValue, new FontRenderContext(currFont.getTransform(), false, false)).getBounds().getWidth(); return (short) Math.ceil(font.getFontHeight() * requiredWidth / cellWidth); // The above solution doesn't handle the newline character, i.e. "\n", and only for row having merged cells. }
public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); size.width = circle.getBounds().width; return size;
offset = new Point(node.getBounds().x - e.getX(), node.getBounds().y - e.getY()); Rectangle bounds = dragged.getBounds(); bounds.setLocation(to); dragged.setFrame(bounds); Point to = node.getBounds().getLocation(); to.x += radius / 2; to.y += radius / 2; int x = node.getBounds().x; int y = node.getBounds().y; int width = node.getBounds().width; int height = node.getBounds().height; g.drawString(text, x + ((width - textWidth)) / 2,
rects.remove(selectedRect); rects.add(rects.size(), selectedRect); deltaPt = new Point(mEvt.getX() - selectedRect.getBounds().x, mEvt.getY() - selectedRect.getBounds().y); repaint(); return; public void mouseDragged(MouseEvent e) { if (selectedRect != null) { Rectangle bounds = selectedRect.getBounds(); bounds.setLocation(e.getX() - deltaPt.x, e.getY() - deltaPt.y); selectedRect.setFrame(bounds.x, bounds.y, bounds.width, bounds.height);
Rectangle bounds = circle.getBounds(); return new Dimension(bounds.width, bounds.height);
Rectangle bounds = fireBall.getBounds();
this.str = str; FontRenderContext frc = new FontRenderContext(null, true, true); rect = parent.getFont().getStringBounds(str, frc).getBounds(); rect.width = Math.max(rect.width, 100); insets = new Insets(0,5,0,rect.width);
if (containerBounds.contains(shape.getBounds())) { delta = Math.min(delta + 0.25, 6d); deltas.put(shape, delta);
return g2d.getFontMetrics().getStringBounds(text, g2d).getBounds().getSize();
glassY = HORIZON - rectHeight; rect.setRect(GLASS_X, glassY, GLASS_WIDTH, rectHeight); System.out.print(rect.getBounds());
Rectangle ballBounds = ball.getBounds(); ball.setFrame(ballBounds); ballBounds.x = rand.nextInt(getWidth() - BALL_SIZE + 1) + 1;
Rectangle textBounds = metrics.getStringBounds(text, g).getBounds(); g.dispose();
Rectangle textBounds = metrics.getStringBounds(text, g).getBounds(); g.dispose();
Rectangle shapeBounds = shape.getBounds(); shapeBounds.x += xDelta; shapeBounds.y += yDelta;
Rectangle bounds = circle.getBounds(); return new Dimension(bounds.width, bounds.height);