[ACCEPTED]-Java : set a Component on top of another-jpanel

Accepted answer
Score: 22

You could replace your main JPanel with 3 a JLayeredPanel. A layered panel will let 2 you specify that some child components should 1 be layered above other child components.

I.e.:

    JLayeredPane pane = new JLayeredPane();

    JLabel ontop = new JLabel("On top");
    JLabel behind = new JLabel("Behind");

    pane.add(ontop, 2, 0);
    pane.add(behind, 1, 0);
Score: 7

Make your main JPanel a JLayeredPane

Then you can set 2 the layer of the other components with setLayer(Component c, int layer) thus 1 allowing them to overlap.

More Related questions