Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
Using negative height in g.fillRect()

Hello I am trying to paint a bar graph using g.fillRect() to make each bar.

The bars will start at the grid height, y: 700, and fill upwards to y: 350 for example.

I am unable to set a negative x-height for my bar:

public void paint(Graphics g) {
    for (Bar b : this.bars) {
        g.fillRect(b.x_location,b.y_location,b.width,b.height * (-1));
    }
}

This won't paint the bars.

Fix:

public void paint(Graphics g) {
    for (Bar b : this.bars) {
        g.fillRect(b.x_location,b.y_location - b.height,b.width,b.height);
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can't, because of the way the API works, it extends down and to the right. Instead, subtract the distance from the y coordinate and maintain the height as a positive value

From the JavaDocs

Fills the specified rectangle. The left and right edges of the rectangle are at x and x + width - 1. The top and bottom edges are at y and y + height - 1. The resulting rectangle covers an area width pixels wide by height pixels tall. The rectangle is filled using the graphics context's current color.

While not a direct duplicate, this example demonstrates the basic concepts

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda