I'm attempting to overlap JPanel
instances. Put a panel directly on another, in the exact same position and exact size. Every time I do this it moves the other panel to the other side or underneath, the previous panel is inside another much larger one and has buttons in it.
How would I do this? Keep in mind it's using the Window Builder tool.
Use a
JLayeredPane
(image below from the linked tutorial)...or a
CardLayout
as shown here....depending on which of those two you mean, since I understand them as quite different effects.
You might also want to look at
OverlayLayout
, seen here. It's not included in the conventional gallery, but it may be of interest.Use a
JDesktopPane
(or its superclassJLayeredPane
) as its content, adding to the pane.See How to Use Internal Frames for examples.
Here you can see a nice way of letting components overlay, and pop up when the cursor rests on it:
Still has some problems, when using components that require focus, but should work well with
JLabel
, andJPanel
.