[SWING] [SOLVED] halving the screen with two seperate panes?

I’m trying to understand how layouts work and I can’t wrap my head around them. What I am trying to accomplish is to have two scroll panes each take up half of the window. At the moment, they both show up but they do not take up half individually, I keep trying to set the sizes of them but it seems to not do anything at all!

These are the panes :

/* Text */
		JPanel contentPane = new JPanel();
		contentPane.setLayout(new GridLayout(1, 2));

		inboxPanel = new JPanel();
		messagePanel = new JPanel(new GridLayout(1, 2));
		inboxPanel.setLayout(new GridLayout(1, 2));
		

This is how I add them :


messagePanel.add(jMessageScrollPane);
		inboxPanel.add(jInboxScrollPane);
		contentPane.add(messagePanel);
		contentPane.add(inboxPanel)

;

Can you please post an MCVE that we can copy and paste to run on our own computers?

My experience of swing layouts was a very similar experience to what you are having now :slight_smile: The issue was because of the complicated nature of how swing uses setSize, setPreferredSize, setMinimumSize, setMaximumSize. This post explains it nicely

Hey I’m sorry about this post in general. I came to check on the site today to see if there is any newbie stuff I could help with and found that I posted a question during a drunken stupor. I do want to thank ziozio for providing a very helpful link. I also fixed it the day after, here’s what I did :

I made my contentPane have a BorderLayout:

JPanel contentPane = new JPanel(new BorderLayout());

I set the dimensions of my panels to have the Jframe width which is 400 (There are two of these but with different names) :

inboxPanel = new JPanel();
inboxPanel.setPreferredSize(new Dimension(400, 600));

Then the VERY important part was adding them to the cotentPane like so :

contentPane.add(messagePanel, BorderLayout.LINE_START);
contentPane.add(inboxPanel, BorderLayout.LINE_END);

Line Start being the left side, and Line End being the right side. Hopefully this will help some newbies like me that happen to stumble upon this problem. Thank you for your patience JGO community and I hope you have a wonderful day!