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);
}
}

