I have two JPanels which have some graphics drawn on the panel. Now I
want to have the two panel overlapping one the same JPanel so that two
graphics on the panels will display together.
Can anyone give some clues how to do this?
Thank you.
> I have two JPanels which have some graphics drawn on the panel. Now I
> want to have the two panel overlapping one the same JPanel so that two
> graphics on the panels will display together.
>
> Can anyone give some clues how to do this?
You need to do two things:
o setOpaque(false)
Opaque may or may not already be false. For a JPanel it depends
upon the installed PL&F. One would also need to set this after PL&F is
changed (the interface between components and PL&F is poorly defined).
o Override isOptimizedDrawingEnabled of the parent container to return
false.
This is a bit of magic to make sure the parent paints its children
correctly. One would have thought it computationally efficient enough
for the container to work it out itself, but unfortunately the poor
optimisation is exposed.
I suggest using JComponent instead of JPanel. JPanel carries with it
unnecessary baggage.
Tom Hawtin