The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > GridBagLayout  [12 examples]

e633. Setting Gap Sizes in a GridBadLayout

Unlike most of the other layout managers, the gridbag layout manager does not have a property for controlling the size of the gaps between cells. You could implement gaps using insets (see e630 Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets. However, this method is tedious and any change in the layout requires major changes with the insets.

The next best method is to create a blank column or row explicitly for the desired gaps.

    // Assume components have been added in cells
    // (0,0), (0,2), (2,0), (2,2)
    
    // Create a 10 pixel gap between columns 0 and 2
    setColumnMinWidth(gbl, 1, 10);
    
    // Create a 10 pixel gap between rows 0 and 2
    setRowMinHeight(gbl, 1, 10);
    
    // setColumnMinWidth() and setRowMinHeight() are defined in
    // e632 Setting a Row or Column of a GridBadLayout to a Particular Size

 Related Examples
e622. Creating a GridBagLayout
e623. Setting the Location of a Component in a GridBagLayout
e624. Getting the Number of Rows and Columns of Cells in a GridBagLayout
e625. Making a GridBagLayout Fill the Container
e626. Setting the Stretchyness of Rows and Columns in a GridBagLayout Using Layout Weights
e627. Setting the Stretchyness of Columns and Rows in a GridBagLayout Using Component Weights
e628. Setting the Stretchyness of a Component Within the Cell of a GridBagLayout Using Fill
e629. Setting the Location of a Component Within the Cell of a GridBagLayout Using Anchors
e630. Setting the Space around a Component Within the Cell of the GridBagLayout Using Insets
e631. Adjusting the Size of a Component in a GridBadLayout Using Internal Padding
e632. Setting a Row or Column of a GridBadLayout to a Particular Size

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    Images    Shapes    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.