Click here to Skip to main content
15,884,537 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
How would i set up a layoutmanager to create a GUI like this?
https://docs.google.com/drawings/d/1te1IpBLzcFnV8KXq4-RMQnRMQviyuaW7vUN0s7jODlA/edit?usp=sharing[^]

i can set up all the actionevents and make the buttons do stuff etc but i just dont know how to position the panels and buttons correctly using a layoutmanager.
Posted
Updated 21-Oct-14 6:28am
v2
Comments
Sergey Alexandrovich Kryukov 21-Oct-14 12:38pm    
What have you tried so far?
I see absolutely nothing special in this layout. It looks fine, by the way.
—SA
lostaballs 22-Oct-14 12:42pm    
i know how to make buttons and jpanels but i have no idea how i would set up the buttons and panels in this arrangement, im not sure where to even begin
Sergey Alexandrovich Kryukov 22-Oct-14 13:06pm    
[Sigh...]

1 solution

Your gui split[^]
You can see that there is a panel beneath those 3 red panels.

EDIT: Think about the coding. Separate GUI and Control, set up a service layer.
You're probably writing a description first (big hint!).

EDIT2:
PLease take a look here: A Visual Guide to Layout Managers[^]

and you might try this simple JFrame. Please create yourself a playground project and try things out there:

Java
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;


public class MyFrame extends JFrame {

	private JPanel panelLeft = new JPanel();
	private JPanel panelRight = new JPanel();
	private JPanel panelLeftTop = new JPanel();
	private JPanel panelLeftBottom = new JPanel();
	
	public MyFrame(){
		this.ignition();
	}
	
	private void ignition() {
		this.setSize(800,600);
		this.setLayout(new GridLayout(1, 2));
		
		panelLeft.setBackground(Color.RED);
		panelRight.setBackground(Color.GREEN);
		panelLeftTop.setBackground(Color.YELLOW);
		panelLeftBottom.setBackground(Color.BLUE);
		
		// inside left panel
		panelLeftTop.setSize(400,300);
		panelLeftBottom.setSize(400,300);
		
		//giving left panel a layout and adding components
		panelLeft.setLayout(new GridLayout(2,1));
		panelLeft.add(panelLeftTop);
		panelLeft.add(panelLeftBottom);
		
		//adding the panels to the JFrame
		this.add(panelLeft);
		this.add(panelRight);
	}

	public static void main(String[] args) {
		new MyFrame().setVisible(true);
	}

}
 
Share this answer
 
v3
Comments
lostaballs 23-Oct-14 10:19am    
Are you suggesting i make one JPanel to group everything on the left side? and one for the right? im confused with what you are saying
TorstenH. 23-Oct-14 11:24am    
I added a link and a simple JFrame to show you how to layout your application.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900