JPanel problem

Hi,

I have 3 JPanel and I want to add Jbuttons to all 3. I have an array of buttons. To the first JPanel I add all the buttons to the second i add the third button from the array and to the last one i want to add all the buttons. I don't understand why the first 2 panels do not appear, and only the last one does.

Pls help

thanks

here is the code :

publicclass TestJpanel{

publicstaticvoid main(String[] args){

JPanel panel =new JPanel();

JPanel panel2 =new JPanel();

JPanel panel3 =new JPanel();

JFrame frame =new JFrame();

frame.getContentPane().setLayout(new GridLayout(3,1));

JButton[] buttons =new JButton[5];

for(int i = 0; i < buttons.length; i++){

buttons[i] =new JButton("Button" + i);

}

for(int i = 0; i < buttons.length ; i++){

panel.add(buttons[i]);

}

frame.getContentPane().add(panel);

panel2.add(buttons[2]);

frame.getContentPane().add(panel2);

for(int i = 0; i < buttons.length ; i++){

panel3.add(buttons[i]);

}

frame.getContentPane().add(panel3);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(800,800);

frame.setVisible(true);

}

}

[2191 byte] By [bluedragonflya] at [2007-11-27 2:48:58]
# 1

well you have to read the swing tutorial to under how the layout manager works.But to get you started here is what you can try.But I suggest you to this

http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

frame.getContentPane().add(panel, BorderLayout.WEST);

frame.getContentPane().add(panel2, BorderLayout.CENTER);

frame.getContentPane().add(panel2, BorderLayout.EAST);

Message was edited by:

well you have to read the swing tutorial to understand how the layout manager works.But to get you started here is what you can try.But I suggest you read this

http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html

frame.getContentPane().add(panel, BorderLayout.WEST);

frame.getContentPane().add(panel2, BorderLayout.CENTER);

frame.getContentPane().add(panel2, BorderLayout.EAST);

cantrya at 2007-7-12 3:19:51 > top of Java-index,Desktop,Core GUI APIs...
# 2

What I need is to have 3 cells with the same size and in every cell add those buttons. GridLayout was perfect for me because each cell is the same size.

The example with BorderLayout doesn't work for me and still it displays only the last JPanel.

If you could tell me more..Thanks..

bluedragonflya at 2007-7-12 3:19:51 > top of Java-index,Desktop,Core GUI APIs...