How to make two JPanel overlapping

I

iherage

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.
 
T

Thomas Hawtin

iherage said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,627
Members
45,329
Latest member
InezZ76898

Latest Threads

Top