Page 2 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , The GridBagLayout class is a flexible layout manager, that aligns components vertically and horizontally,, , without requiring that the components be of the same, size., , DJ Sir
Page 3 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying, , one or more cells, called its display area., , , The java.awt.GridBagLayout layout manager is the most, powerful and flexible of all the predefined layout, managers but more complicated to use., , DJ Sir
Page 4 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , Unlike GridLayout where the component are arranged in, a rectangular grid and each component in the container is, , forced to be the same size., , , But in GridBagLayout, components are also arranged in, rectangular grid but can have different sizes and can, occupy multiple rows or columns., , DJ Sir
Page 5 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , What makes the gridbag useful is that you can specify, the relative placement of components by specifying their, , positions within cells inside a grid., , , The key to the grid bag is that each component can be a, different size, and each row in the grid can have a, different number of columns., , DJ Sir
Page 6 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , This is why the layout is called a gridbag., , , , It’s a collection of small grids joined together., , , , The location and size of each component in a gridbag are, , determined by a set of Constraints linked to it., , , The constraints are contained in an object of type, , GridBagConstraints., DJ Sir
Page 7 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , Constraints include the height and width of a cell, and, the placement of a component, its alignment, and its, , anchor point within the cell., , , The general procedure for using a grid bag is to first, create GridBagLayout object and to make it the current, layout manager., , DJ Sir
Page 8 :
1.4 Use of Layout Managers:, , , GridBagLayout :, , , , Then, set the constraints that apply to each component, that will be added to the grid bag. Finally, add the, , components to the layout manager., , DJ Sir
Page 9 :
1.4 Use of Layout Managers:, , , GridBagLayout :Constructor, , , , GridBagLayout defines only one constructor., , , , GridBagLayout()- Creates a grid bag layout manager., , , , A GridBagLayout layout manager requires a lot, , of information to know where to put a component in a, container. A helper class called GridBagConstraints, provides all this information., DJ Sir
Page 10 :
1.4 Use of Layout Managers:, , , GridBagLayout : Methods, , , , GridBagLayout defines several methods, of which many, are protected and not for general use. There is one, , method, setConstraints( ) is used to set the constraint to, the each component in the grid bag., , DJ Sir
Page 11 :
1.4 Use of Layout Managers:, , , GridBagLayout : Methods, void setConstraints(Component comp,, GridBagConstraints cons), , , , Here, comp is the component for which the constraints, , specified by cons apply. The key to successfully using, GridBagLayout is the proper setting of the constraints,, which are stored in a GridBagConstraints object., DJ Sir
Page 12 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , GridBagConstraints defines several fields that you can, set to govern the size, placement, and spacing of a, , component., , DJ Sir
Page 13 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , int gridx, , int gridy, , DJ Sir, , DESCRIPTION, , Specifies the X coordinate of the cell to which the, component will be added., The default value is, GridBagConstraints.RELATIVE., Specifies theY coordinate of the cell to which the, component will be added. The default value is, GridBagConstraints.RELATIVE.
Page 14 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Specifies the grid cell (column=x and row=y) that the, upper left of the component will be displayed in, where, , the upper-left-most grid cell has address gridx = 0, gridy, = 0., , DJ Sir
Page 15 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Use GridBagConstraints.RELATIVE (the default value), to specify that the component should be placed just to the, , right of (for gridx) or just below of (for gridy) the, component that was added to the container just before, this component was added., , DJ Sir
Page 17 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , DESCRIPTION, , int gridheight Specifies the height of component in terms of cells.The, default is1., int gridwidth Specifies the width of component interms of cells.The, default is1., Insets insets Specifies the insets., Default insets are all zero., , DJ Sir
Page 18 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Specifies the number of columns (gridwidth) and rows, (gridheight) that the component will occupy. The default, , value is 1., , , Use GridBagConstraints.REMAINDER to specify that, the component be the last one in its row (for gridwidth), or column (for gridheight)., , DJ Sir
Page 20 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Specifies the component's external padding, the, minimum amount of space between the component and, , the edges of its display area., , , To do this, we make an instance of the Insets class (e.g., new Insets(10, 10, 10, 10)). The order of the parameters, for this constructor is top, left, bottom then right., , DJ Sir
Page 23 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Used when the component is smaller than its display area, to determine where (within the display area) to place the, , component. Also, when resizing, this allows the, component to be fixed at a corner or edge., , DJ Sir
Page 27 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , int fill, , DJ Sir, , DESCRIPTION, , This field is used when the component’s display area is, larger than the component’s size. It tells whether to, resize the component or not when the frame is resized., Valid values are:, GridBagConstraints.NONE(the default),, GridBagConstraints.HORIZONTAL,, GridBagConstraints.VERTICAL,, GridBagConstraints.BOTH.
Page 28 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Used in resizing when the component's display area is, larger than the component's requested size to determine, , how to resize the component., , , Possible values are:, , , GridBagConstraints.NONE (the default - the component will, not grow in either direction), , DJ Sir
Page 29 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , GridBagConstraints.HORIZONTAL (make the component, wide enough to fill its display area horizontally, but don't, change its height),, , , , GridBagConstraints.VERTICAL (make the component tall, enough to fill its display area vertically, but don't change its, width), and, , DJ Sir
Page 30 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , GridBagConstraints.BOTH (make the component fill its, display area entirely)., , DJ Sir
Page 31 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , int ipadx, , int ipady, , DJ Sir, , DESCRIPTION, , Specifies extra horizontal space that surrounds a, component within a cell., The default is 0., Specifies extra vertical space that surrounds a, component within a cell., The default is 0.
Page 32 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Specifies the component's internal padding (spacing, around the component) within the layout, how much to, , add to the minimum size of the component., , , Since the GridBagLayout manager lays out the, components such that the grid sizes are not specified, explicitly, each component is given a minimum size., , DJ Sir
Page 33 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Sometimes, we would like a component to have a larger, minimum size., , , , Using these constraints we can set the width of the, component to be at least its minimum width plus (ipadx, , * 2) pixels (since the padding applies to both sides of the, component)., DJ Sir
Page 34 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Similarly, the height of the component will be at least the, minimum height plus (ipady * 2) pixels., , DJ Sir
Page 35 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , double, weightx, , DJ Sir, , DESCRIPTION, , Specifies a weight value that determines the, horizontal spacing between cells and the edges of the, container that holds them., The default value is 0.0., The greater the weight, the more space that is, allocated., If all values are 0.0, extra space is distributed evenly, between the edges of the window.
Page 36 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , VARIABLE, , double, weighty, , DJ Sir, , DESCRIPTION, , Specifies a weight value that determines the vertical, spacing between cells and the edges of the container, that holds them., The default value is 0.0., The greater the weight, the more space that is, allocated., If all values are 0.0, extra space is distributed evenly, between the edges of the window.
Page 37 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Used to determine how to distribute space when resizing, the window., , , , A zero value indicates the component does not grow, horizontally/vertically on its own. Components with, , larger weight values will occupy more of the additional, space than components with small weight values., DJ Sir
Page 38 :
1.4 Use of Layout Managers:, , , GridBagLayout : GridBagConstraints, , , , Unless you specify a weight for at least one component in, a row (weightx) and column (weighty), all the components, , clump together in the center of their container., , , This is because when the weight is zero (the default), the, GridBagLayout object puts any extra space between its, grid of cells and the edges of the container., , DJ Sir
Page 40 :
1.4 Use of Layout Managers:, , , GridBagLayout :Example, , DJ Sir
Page 41 :
1.4 Use of Layout Managers:, , , GridBagLayout :Example, , DJ Sir