The problem here is that you override the paintComponent()
method of your layered pane, not the JPanel
. The JPanel
will paint itself later, as one of the children of your layered pane, and this will wipe out what you painted.
In general, a paintComponent()
method should paint into the Graphics
that was given to it, not into some other component's graphics.