The Java Developers Almanac 1.4


Order this book from Amazon.

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

e623. Setting the Location of a Component in a GridBagLayout

A gridbag layout arranges components in a two-dimensional grid of cells. The northwest-most cell has position (0,0). The cell to the right or east has position (1,0); the cell to the bottom or south has position (0,1).

The size of the grid grows dynamically. For example, if you place a component at position (2,1) in a new empty gridbag layout, the layout will automatically have a size of 3 cells across by 2 cells down.

See e622 Creating a GridBagLayout for an example on how to use a gridbag layout with gridbag constraints.

    GridBagConstraints gbc = new GridBagConstraints();
    
    // Place a component at (1,1)
    gbc.gridx = 1;
    gbc.gridy = 1;
    gbl.setConstraints(component1, gbc);
    container.add(component1);
    // The layout now has 4 cells
    
    // Place a component at (0,0)
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbl.setConstraints(component2, gbc);
    container.add(component2);

 Related Examples
e622. Creating 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
e633. Setting Gap Sizes in a GridBadLayout

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


© 2002 Addison-Wesley.