Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright 1998-2005 Curt Hill GridBag Layout Manager A flexible but complicated layout.

Similar presentations


Presentation on theme: "Copyright 1998-2005 Curt Hill GridBag Layout Manager A flexible but complicated layout."— Presentation transcript:

1 Copyright 1998-2005 Curt Hill GridBag Layout Manager A flexible but complicated layout

2 Copyright 1998-2005 Curt Hill Is this the best or worst? Very flexible and complicated Allows different sized components Each component has constraints which determine its positioning It allows merging of cells Most of the work is done by an object of GridBagConstraints When it does not work it is seldom clear why

3 Copyright 1998-2005 Curt Hill GridBag Has only default constructor The number of rows and columns is determined by the constraints of the added components Each component occupies a rectangle of cells The adds are somewhat different than expected

4 Copyright 1998-2005 Curt Hill Adding to the layout manager Three steps: Establish the constraints –This is most of the work Use the setConstraints –Connects the constraints and component Do the add –Add has only parameter: a component

5 Copyright 1998-2005 Curt Hill GridBagConstraints An object that effectively describes the formatting of the component Specifies –x,y positions –sizes –Alignment –filling

6 Copyright 1998-2005 Curt Hill GridBagConstraints properties Unlike very many objects most properties are public, rather than private or protected Thus we can merely do assignments on them before executing the setConstraints method The properties usage follows

7 Copyright 1998-2005 Curt Hill Position Properties int gridx –Position of left portion –Zero is leftmost int gridy –Position of top –Zero is top These determine the upper left corner of the component’s rectangle

8 Copyright 1998-2005 Curt Hill Size Properties int gridwidth and gridheight –Determines the number of rows and columns in this component fill – enlarge to limits of the rectangle –Set to one of four constants HORIZONTAL VERTICAL NONE – no filling BOTH – fill in both directions

9 Copyright 1998-2005 Curt Hill Other padding properties insets, a class of four integers This specifies external padding This is the padding between the component and its rectangular boundary The Inset has the following constructor parameters: –(int top, int left, int bottom, int right)

10 Copyright 1998-2005 Curt Hill Alignment property Anchor –How to place an item that is smaller than its rectangle May be one of several constants: –CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, and NORTHWEST


Download ppt "Copyright 1998-2005 Curt Hill GridBag Layout Manager A flexible but complicated layout."

Similar presentations


Ads by Google