Vertical sequence of components.

publicclass LayoutTestextends JFrame{

public LayoutTest(){

this.setLayout(null);

JButton bt1 =new JButton("button1");

bt1.setBounds(0, 0, 100, 40);

JButton bt2 =new JButton("button2");

bt2.setBounds(0, 50, 100, 40);

JButton bt3 =new JButton("button3");

bt3.setBounds(0, 100, 100, 40);

JPanel p1 =new JPanel();

p1.setLayout(null);

p1.setBackground(Color.green);

p1.setBounds(50, 50, 100, 150);

p1.add(bt1);

p1.add(bt2);

p1.add(bt3);

JLabel label =new JLabel("hello!");

label.setBounds(140, 100, 100, 50);

label.setBackground(Color.orange);

label.setOpaque(true);

JLayeredPane layer =new JLayeredPane();

layer.add(label,new Integer(1));

layer.add(p1,new Integer(2));

this.setContentPane(layer);

this.setSize(300,300);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstaticvoid main(String args[]){

LayoutTest lt =new LayoutTest();

lt.setVisible(true);

}

In this code, I was trying to put a JLabel component on a JPanel components. But whatever I do, the JLabel component is always under the JPanel component.

Is there somebody can explain what is the problem, and how to fix this problem.

Many thanks.

[2220 byte] By [scott_kim] at [2007-11-26 12:05:31]
# 1
label.setBounds(140, 100, 100, 50);Pay attention to where you are placing the components.
CaptainMorgan08 at 2007-7-7 12:33:01 > top of Java-index,Security,Cryptography...
# 2
Thanks for your reply.Yes. Im sure where Im placing the component.Cause, Im planing to move the JLabel with some kinds of event.I just dont want to let the JLabel be under the JPanel, thus let the JLabelcomponent always keep visible.
scott_kim at 2007-7-7 12:33:01 > top of Java-index,Security,Cryptography...