problem with BorderLayout

How can I make 'panel' (in the center ) stretch vertically and horizontally to fill the complete space in between the North and South areas of the BorderLayout?
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTree;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;

public class Main extends JFrame {

	private static final long serialVersionUID = -573737534454859870L;
	private JPanel contentPane;
	private JPanel northPanel;
	private JButton btnNew;
	private JButton btnOpen;
	private JButton btnSave;
	private JPanel southPanel;
	private JLabel statusLabel;
	private JTree tree = null;
	private JTabbedPane tabbedPane = null;
	private JSplitPane splitPane;
	private JScrollPane scrollPane;
	private JScrollPane scrollPane_1;
	private JTextArea textArea;
	private JTable table = null;
	private JScrollPane scrollPane_2;
	private JSplitPane centerSplit;

	 * Launch the application.
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main frame = new Main();
				} catch (Exception e) {

	 * Create the frame.
	public Main() {
		setBounds(100, 100, 750, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(1, 1));
		northPanel = new JPanel();
		northPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		contentPane.add(northPanel, BorderLayout.NORTH);
		btnNew = new JButton("New");
		btnOpen = new JButton("Open");
		btnSave = new JButton("Save");

		southPanel = new JPanel();
		southPanel.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		contentPane.add(southPanel, BorderLayout.SOUTH);
		tabbedPane = new JTabbedPane();
		centerSplit = new JSplitPane();
		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		splitPane = new JSplitPane();
		tabbedPane.addTab("New tab", null, splitPane, null);
		scrollPane = new JScrollPane();
		textArea = new JTextArea();
		textArea.setPreferredSize(new Dimension(600,200));
		scrollPane_1 = new JScrollPane();
		table = new JTable();
		statusLabel = new JLabel("");
		scrollPane_2 = new JScrollPane();
		tree = new JTree();
		tree.setPreferredSize(new Dimension(100,200));


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
thats actually how its works
your problem is the (default) FlowLayout used by the panel you add to the center

            centerSplit = new JSplitPane();
            JPanel panel = new JPanel(new BorderLayout());
            contentPane.add(panel, BorderLayout.CENTER);

or just add the split pane to the content pane directly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
objects is completely right.
Maybe some extra explanation is welcome.

>> How can I make 'panel' (in the center ) stretch vertically and horizontally to fill the complete space in between the North and South areas of the BorderLayout?
The component placed in the center of a BorderLayout takes up all available space (not used by the components in the north, south, west and east) by design.
So in your case, 'panel' is stretched the way you want.

But since you defined it as

         JPanel panel = new JPanel();

it has a FlowLayout by default. (since not specifying a layout for a JPanel == means ==> FlowLayout is used by default)

This means that 'panel' won't use all the available space of the center of its parent container "contentPane" (only what it needs)

You can force your panel to also stretch "together with its parent container" by giving it the BorderLayout:

       JPanel panel = new JPanel(new BorderLayout());

and add the centerSplit component in its center by writing

       panel.add(centerSplit, BorderLayout.CENTER);

or for short:

        panel.add(centerSplit);  // If you don't specify the position when adding a component to a panel having BorderLayout, it's BorderLayout.CENTER by default

I hope that makes the things as clear as possible.
zzynxSr. Software engineerCommented:
thanx 4 axxepting
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.