I have the following Java Swing problem: a parent panel doesn’t get painted (i.e. paintComponent() not even called) when it is covered by another panel which has a transparent background.
I guess this behavior is normal if the child panel isn’t transparent but here it is an issue since the parent panel provides a picture as background.
Probably not relevant but you never know: child panel is a ChartPanel from JFreeChart’s library (extends JPanel) and parent panel is also a JPanel extension, hereby the paintComponent code:
@Override
public void paintComponent(Graphics g) {
try {
long start = System.currentTimeMillis();
//Sets waiting cursor
GuiHelper.setCursorOnEntireWindow(Cursor.WAIT_CURSOR);
//Paints parent
super.paintComponent(g);
//Paints background and other elements
g.drawImage(generateBackground(getWidth(), getHeight()), 0, 0, getWidth(), getHeight(), this);
long end = System.currentTimeMillis();
System.out.println("Chart paint took: "+(end-start)+"ms");
}
finally {
//Removes waiting cursor
GuiHelper.setCursorOnEntireWindow(Cursor.getDefaultCursor().getType());
}
}
Any help/hint would be greatly appreciated as I’ve been looking into for hours now.
Thanks!
Not sure how you are setting the transparent background of ChartPanel. I think you just need to use:
If this doesen’t work then check out Background With Transparency for more information on how painting is done between child/parent components.