Java: JLayeredPane in Netbeans

6k views Asked by At

I am using netbeans IDE to develop a GUI for a java program. I want to use a JLayeredPane in my GUI. I added a JPanel(jPanel5) and a Canvas(canvas) on two layers to my jLayeredPane and This code is generated:

    jPanel5.setBounds(0, 0, 749, 549);
    jLayeredPane1.add(jPanel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
    canvas1.setBounds(0, 0, 40, 30);
    jLayeredPane1.add(canvas1, javax.swing.JLayeredPane.DEFAULT_LAYER);

As you know, this code can not be edited. I don't want these to be on same layer(DEFAULT_LAYER). I used method setLayer() method as:

    jLayeredPane1.setLayer(canvas1 , 2);
    jLayeredPane1.setLayer(jPanel5 , 1);

but still I'm not sure that my porpose is achived.

How can I set these tow components on two layers ?

Thank you !

1

There are 1 answers

1
AudioBubble On BEST ANSWER

Select the panel you want to change in the GUI editor.

Then in the "Properties" Window, scroll down to the "Layout" section. There you'll find a property "Layer" where you can either choose a predefined value, or simply type in the layer you want.

In general: code that is in a "guarded" section is always controlled through the properties of the component (or it's ancestor).

Screenshot of the NetBeans Properties