You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a rounded panel that is inside a Panel with a BackgroundImage painted over it using PaintComponent. Problem is, this happens:
My actual code is:
For the Background Panel:
publicclassJPanelBackgroundextendsJPanel {
privateBufferedImagebackgroundImage;
publicJPanelBackground(StringimagePath) throwsIOException {
backgroundImage = ImageIO.read(newFile(imagePath));
}
@OverrideprotectedvoidpaintComponent(Graphicsg) {
super.paintComponent(g);
intpanelWidth = getWidth();
intpanelHeight = getHeight();
// Obtener el ancho y alto de la imagen de fondointimageWidth = backgroundImage.getWidth();
intimageHeight = backgroundImage.getHeight();
// Calcular la relación de aspecto de la imagendoubleaspectRatio = (double) imageWidth / imageHeight;
// Calcular el ancho y alto de la imagen para que se ajuste al panel manteniendo la relación de aspectointscaledWidth = panelWidth;
intscaledHeight = (int) (panelWidth / aspectRatio);
// Si la altura escalada es menor que la altura del panel, recalcula el ancho y alto para ajustar a la altura del panelif (scaledHeight < panelHeight) {
scaledHeight = panelHeight;
scaledWidth = (int) (panelHeight * aspectRatio);
}
// Calcular las coordenadas de dibujo para centrar la imagenintx = (panelWidth - scaledWidth) / 2;
inty = (panelHeight - scaledHeight) / 2;
// Dibujar la imagen de fondo escalada y centrada en el panelg.drawImage(backgroundImage, x, y, scaledWidth, scaledHeight, this);
}
}
I have a rounded panel that is inside a Panel with a BackgroundImage painted over it using PaintComponent. Problem is, this happens:
My actual code is:
For the Background Panel:
For the Rounded Panel;
putClientProperty( FlatClientProperties.STYLE, "arc: 90" ); setBackground( Color.red);
Is this a problem, or is this a Skill Issue from my behalf?
The text was updated successfully, but these errors were encountered: