Add buttons in Border Layout

I would like to add buttons in Border Layout one after another . But I do not know how . Thats a part of my code :

setLayout(new BorderLayout());
JPanel jp = new JPanel();
JPanel jp2 = new JPanel();
JPanel jp3 = new JPanel();

add(jp, BorderLayout.SOUTH);
add(jp2, BorderLayout.EAST);
add(jp3, BorderLayout.WEST);

jp.add(btn, BorderLayout.WEST);
jp.add(btn2, BorderLayout.CENTER);
jp.add(btn3, BorderLayout.EAST);

jp2.add(btn4, BorderLayout.NORTH);
jp2.add(btn5, BorderLayout.NORTH);
jp2.add(btn6, BorderLayout.CENTER);
jp2.add(btn7, BorderLayout.SOUTH);
jp2.add(btn8, BorderLayout.SOUTH);

But it add buttons side by side . I am beginner programmer and I really do not idea how to do it .


BorderLayout is not suited for what you want - it supports only one component for each constraint (NORTH, SOUTH...)

Use another layout, there are a lot of options, like Gridlayout, GridBagLayout.

I would use TableLayout, it's a very flexible layout - see the homepage address below.

JPanel initially has FlowLayout, which places components side by side. Instead of new JPanel(), use new JPanel(new BorderLayout())

Need Your Help

Postgresql with Npgsql “relation <tablename> does not exist.” Only occurring on Win 7

c# postgresql

I'm running into a very strange bug when using Postgresql using the Npgsql (2.0.11 and DLL in .NET 3.5.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.