Results 1 to 1 of 1
  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    121
    Rep Power
    0

    Default Components (JPanels) appear extra small in GridBagLayout.

    I added a JPanel to the CENTER position of a JFrame, and now I am adding two panels to that panel. I want the right panel to be double the width of the left panel, (and also for practicing the GridBagLayout), and I also want the panels to expand proportionally when the window is expanded, so I am using GridBagLayout.

    The problem is that the panels turn out to be very very small and in the centre of the page, as you can see in the image. I need to fix this.

    I am posting the part of the code in which I have set the layout and set the constraints. Please point out which GridBagLayout constraints I might have used wrong, or which should I use, so that both the panels cover up the entire parent panel such that the iDetailsPanel is double the size of the iListPanel..

    Java Code:
    //Set Layout
    		setLayout(new GridBagLayout());
    		GridBagConstraints c= new GridBagConstraints();
    		
    		//Set Layout constraints of components and add them to the MainPanel
    		c.gridx=0;
    		c.gridy=0;
    		c.weightx=0.5;
    		c.insets= new Insets(5,5,5,5);
    		c.fill=GridBagConstraints.BOTH;
    		add(iListPanel);
    		iListPanel.setBorder(BorderFactory.createTitledBorder("Check") );
    		
    		GridBagConstraints c1= new GridBagConstraints();
    		c.gridx=1;
    		c.gridy=0;
    		c.weightx=1;
    		c.insets= new Insets(5,5,5,5);
    		c.fill=GridBagConstraints.BOTH;
    		add(iDetailsPanel);
    		iDetailsPanel.setBorder(BorderFactory.createTitledBorder("Check"));
    Components (JPanels) appear extra small in GridBagLayout.-15.png
    Last edited by Zarah; 05-02-2014 at 08:08 PM.

Similar Threads

  1. set Components to GridbagLayout
    By ShadowWalker in forum New To Java
    Replies: 2
    Last Post: 01-02-2014, 09:00 PM
  2. GridBagLayout - forcing all components to stay on top
    By Serpenthelm in forum AWT / Swing
    Replies: 3
    Last Post: 01-05-2012, 07:52 PM
  3. GridBagLayout and JFrames/JPanels!
    By ToXSiK in forum AWT / Swing
    Replies: 1
    Last Post: 05-12-2011, 05:09 AM
  4. Adding and removing components from a GridBagLayout
    By peterhabe in forum New To Java
    Replies: 4
    Last Post: 09-19-2010, 11:13 PM
  5. Arrange components in a GridBagLayout
    By ze snow in forum New To Java
    Replies: 1
    Last Post: 02-27-2010, 03:22 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
  •