Lorsque je google cette méthode. Cela montre qu'il retourne la hauteur du composant courant. Je suis confus parce que quand j'utilise getHeight() dans public void paintComponent (Graphics g) il renvoie la valeur que je ne sais pas d'où il vient. Je me demande s'il y a une hauteur ou une largeur par défaut pour paintComponent? Je vous remercie. Vous pouvez voir le code ci-dessous.comment getHeight() fonctionne dans java en particulier dans paintComponent
public void paintComponent(Graphics g) {
super.paintComponent(g);
// Find the maximum value in the data
double max = data[0];
for (int i=1; i<data.length; i++)
max = Math.max(max, data[i]);
int barWidth = (int)((getWidth() - 10.0)/data.length - 10);
int maxBarHeight = getHeight() - 30;
g.drawLine(5, getHeight() - 10, getWidth() - 5, getHeight() - 10);
int x = 15;
for (int i = 0; i < data.length; i++) {
g.setColor(colors[i % colors.length]);
int newHeight = (int)(maxBarHeight * data[i]/max);
int y = getHeight() - 10 - newHeight;
g.fillRect(x, y, barWidth, newHeight);
g.setColor(Color.black);
g.drawString(dataName[i], x, y - 7);
x += barWidth + 10;
}
}