Results 1 to 3 of 3
  1. #1
    Bagzli is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

    Default Layouts and Sizes

    Hi, I was wondering if somebody can help me out with a way to do this. I need to create a layout that has 4 places, all should be same sizes and the panels needs to be same length all the time.

    here is a picture how i want it to look, also I am putting my code with picture of results i get with this code.

    I want it to look like this:

    http://imageshack.us/photo/my-images...siredlook.jpg/

    This is my code
    Java Code:
    package container;
    
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.geom.Rectangle2D;
    
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class trailer extends JFrame
    {
    	private JPanel pnl_topView = new JPanel();
    	private JPanel pnl_leftView = new JPanel();
    	private JPanel pnl_rightView = new JPanel();
    	private JPanel pnl_threePanels = new JPanel();
    	private JPanel pnl_bottom = new JPanel();
    	
    	private void initialize()
    	{
    		pnl_leftView.setBorder(BorderFactory.createLineBorder(Color.black));
    		pnl_leftView.setSize(100, 100);
    		pnl_rightView.setBorder(BorderFactory.createLineBorder(Color.black));
    		pnl_rightView.setSize(200, 200);
    		pnl_topView.setBorder(BorderFactory.createLineBorder(Color.black));
    		pnl_topView.setSize(300, 300);
    		pnl_bottom.setBorder(BorderFactory.createLineBorder(Color.black));
    		
    		pnl_threePanels.setLayout(new BorderLayout());
    	}
    	
    	private void addToPanels()
    	{
    		pnl_threePanels.add(pnl_topView, BorderLayout.NORTH);
    		pnl_threePanels.add(pnl_rightView, BorderLayout.CENTER);
    		pnl_threePanels.add(pnl_leftView, BorderLayout.SOUTH);
    	}
    	
    	public trailer()
    	{
    		this.setSize(500, 500);
    		this.setTitle("Trailer Panel Loader");
    		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		this.setLocationRelativeTo(null);
    		this.setResizable(false);
    		
    		this.add(pnl_threePanels, BorderLayout.NORTH);
    		this.add(pnl_bottom, BorderLayout.SOUTH);
    		
    		initialize();
    		addToPanels();
    	}
    	
    	public static void main(String[] args)
    	{
    		new trailer().setVisible(true);
    	}
    }
    With the code it looks like this
    http://imageshack.us/photo/my-images...rrentlook.jpg/

    I understand that border layout can not preset sizes, i Just don't know any other way that i can set a size to a panel and make it show full size without it being packed to minimum size?
    Last edited by Bagzli; 07-01-2011 at 06:16 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Why not use a simple GridLayout with four rows and a single column?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Bagzli is offline Member
    Join Date
    Feb 2011
    Posts
    63
    Rep Power
    0

Similar Threads

  1. Setting sizes to JButtons in grid layout
    By sarah jain in forum AWT / Swing
    Replies: 8
    Last Post: 02-22-2011, 05:08 AM
  2. problems with layouts !
    By ron2794 in forum NetBeans
    Replies: 1
    Last Post: 12-15-2010, 02:23 AM
  3. Can you have multiple layouts using swing?
    By fresh83 in forum New To Java
    Replies: 2
    Last Post: 12-27-2009, 10:38 PM
  4. Changing JPanel sizes
    By Basit in forum Java Applets
    Replies: 2
    Last Post: 08-12-2009, 07:48 PM
  5. Layouts ?
    By plodos in forum Eclipse
    Replies: 3
    Last Post: 07-30-2007, 04:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •