Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: [Help] Arranging Objects please help

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    Default [Help] Arranging Objects please help

    Okay, I'm using GridBagLayout to position my items, but I'm trying to put about 4 buttons up in a corner, and if I do:
    BorderLayout.WEST, it goes to the left side, but it goes to the middle, and I don't know how to do this because I'm a beginner.

    Heres my code:

    JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    JButton button = new JButton("Update");
    c.gridx = 0;
    c.gridy = 0;
    panel.add(button, c);

    How would I change that code to put it in the corner?

    Here's a picture of the program. The red means where I need the buttons.

    and if the picture doesn't show up here's the Link:

    Thanks, please reply as soon as possible.
    Last edited by JoelE21101; November 20th, 2011 at 11:22 PM.

  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    My Mood
    Thanked 167 Times in 158 Posts

    Default Re: [Help] Arranging Objects please help

    Rarely can you achieve what you want with only one panel and one layout manager. What you will need to do is place your buttons on a separate panel with whatever layout you need and then add that panel to the main panel. Or you might need to nest several panels inside one another.
    Improving the world one idiot at a time!

Similar Threads

  1. Aranging objects on a Gui
    By frozen java in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 20th, 2011, 06:45 PM
  2. all objects in array the same?
    By abrohm in forum What's Wrong With My Code?
    Replies: 6
    Last Post: June 17th, 2011, 11:21 AM
  3. New to Objects...
    By Java Neil in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 24th, 2011, 07:00 AM
  4. Arranging words in a sentence in alphabatical order.
    By J2000 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 24th, 2011, 10:04 AM
  5. Objects
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: January 20th, 2010, 12:50 PM