Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / October 2004

Tip: Looking for answers? Try searching our database.

GridBagConstraints anchor dilemma

Thread view: 
Gary V - 29 Oct 2004 19:30 GMT
I am trying line up a single column of several buttons on the left
(West) side of a container but have not been successful. Here is a
simple code example to illustrate how I am attempting this:

import java.awt.*;

public class Vertical extends Frame {

   public static void main(String argv[]) {
       new Vertical().show();
   }

   public Vertical() {
       Button btn;
       GridBagLayout gridbag = new GridBagLayout();
       setLayout(gridbag);

       GridBagConstraints constraints = new GridBagConstraints();
       constraints.gridx = 0;
       constraints.gridy = GridBagConstraints.RELATIVE;
       constraints.anchor = GridBagConstraints.WEST;

       for (int n = 1; n <= 8; n++) {
           btn = new Button("Button " + n);
           add(btn);
           gridbag.setConstraints(btn, constraints);
       }

       resize(300, 300);
   }
}

When run the buttons are lined up in the center of the Frame. Any
ideas how to anchor the buttons on the left?

Gary V
Chris Rohr - 31 Oct 2004 14:35 GMT
You need to set up a fill on your constraints.  Your buttons are to the
west of its current area, but it doesn't fill across the entire space.

Just add the following constraint option:
constraints.fill = GridBagConstraints.HORIZONTAL;

Chris

> I am trying line up a single column of several buttons on the left
> (West) side of a container but have not been successful. Here is a
[quoted text clipped - 32 lines]
>
> Gary V


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.