Results 1 to 2 of 2
  1. #1
    orushw is offline Member
    Join Date
    May 2011
    Rep Power

    Default Problem with GridBagLayout.

    I'm using the GridBagLayout manager and i want to add my first button at the left corener of my frame (0,0).
    The button locate him self to the center of my frame, and i dont know how to move it to the left corener.
    This is what i want to do :
    Problem with GridBagLayout.-button.png
    I want to locate the button at the red place.
    This is my code :
    Java Code:
    import javax.swing.*;
    import java.awt.*;
    public class Display {
    	private JFrame frame;
    	private JPanel panel;
    	private JList<String> list;
    	public Display()
    		frame = new JFrame();
    		panel = new JPanel(new GridBagLayout());
    		list = new JList<String>();
    		GridBagConstraints grid = new GridBagConstraints();
    		//Set the spaces between the components and order them VERTICAL.
    		grid.fill = GridBagConstraints.VERTICAL;
    		grid.insets = new Insets(15,15,15,15); 
    		int day_of_week = 7;
    		for(int i=0;i<28;i++)
    			grid.gridx = i % 7;
    			grid.gridy = i / 7 ;
    			list = new JList<String>();
    How do i use the GridBagLayout to locate the button there?
    Thanks alot,

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Problem with GridBagLayout.

    You're not setting all the pertinent fields of the GridBagConstraints object. Look at the API and the tutorial. For example you'll want to set the weight constraints among others.

Similar Threads

  1. GridBagLayout Component Problem...
    By danpotter in forum AWT / Swing
    Replies: 5
    Last Post: 05-10-2012, 12:34 AM
  2. GridBagLayout alignment problem
    By adwart in forum AWT / Swing
    Replies: 2
    Last Post: 08-15-2011, 05:58 AM
  3. GridBagLayout problem!
    By canersen in forum AWT / Swing
    Replies: 9
    Last Post: 03-07-2011, 12:35 AM
  4. Problem with GridBagLayout
    By ze snow in forum New To Java
    Replies: 20
    Last Post: 02-28-2010, 07:08 AM
  5. Problem with GridBagLayout
    By Daniel in forum SWT / JFace
    Replies: 2
    Last Post: 07-01-2007, 07:57 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