I wish to paint and repaint a JPanel, which may be rotated 90 degrees with images. The initial painting does not cause any issues. When I try to repaint() the panel it will not do this immediately, but wait for a second repaint().
My second issue is that, when i turn my panel vertical as stated in the below code, it will not repaint at all. I can't see the image red, yellow or green at least, but the image "light" remains.
Thank you for taking your time to read this.
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if(vertical){
g2d.translate(this.getWidth() / 2, this.getHeight() / 2);
g2d.rotate(-Math.PI / 2);
g2d.translate(-img_light.getWidth(null) / 2, -img_light.getHeight(null) / 2);
g2d.drawImage(img_light, 0, 0, this);
if(showRed){
g2d.translate(-img_red.getWidth(null) / 2, -img_red.getHeight(null) / 2);
g2d.drawImage(img_red, 0, 0, null);
}
if(showYellow){
g2d.translate(-img_yellow.getWidth(null) / 2, -img_yellow.getHeight(null) / 2);
g2d.drawImage(img_yellow, 0, 0, null);
}
if(showGreen){
g2d.translate(-img_green.getWidth(null) / 2, -img_green.getHeight(null) / 2);
g2d.drawImage(img_green, 0, 0, null);
}
}else{
g2d.drawImage(img_light, 0, 0, this);
if(showRed){
g2d.drawImage(img_red, 0, 0, null);
}
if(showYellow){
g2d.drawImage(img_yellow, 0, 0, null);
}
if(showGreen){
g2d.drawImage(img_green, 0, 0, null);
}
}
}