I'm trying to create a graphic interface using JPanel
and JButton
. So far it's good except when I'm creating the JButton
instances, they seem to align within the same line. I want every button to be in one line, not all in the same line.
How do I achieve the desired effect?
public class Interface extends JFrame{
public Interface ()
{
//frame
super("Panel");
pack();
setSize(500,400);
setVisible(true);
//declaration container
Container c;
c=getContentPane();
c.setLayout(new BorderLayout());
//declaration des panel avec leurs caracteristiques
JPanel menu =new JPanel();
JPanel MessageList =new JPanel();
JPanel about=new JPanel();
menu.setLayout(new FlowLayout());
MessageList.setLayout(new FlowLayout());
about.setLayout(new FlowLayout());
menu.setBackground(Color.blue);
MessageList.setBackground(Color.cyan);
about.setBackground(Color.cyan);
c.add(menu,BorderLayout.WEST);
c.add(MessageList,BorderLayout.EAST);
c.add(about,BorderLayout.SOUTH);
//--------Button---------------------
JButton button1=new JButton("button1");
JButton button2=new JButton("Button2");
menu.add(button1);
menu.add(button2);
//-----------------------------
}
public static void main(String args[])
{
Interface Message=new Interface();
Message.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}