Adding or moving components within GridBagLayout

When you build your application visually using GridBagLayout, the visual grid markers help you to move and drop components in the required position.

To add or move components within GridBagLayout:

  1. Select the Swing component from the palette that you want to add to your GridBagLayout, or click and drag the existing component that you want to move within your GridBagLayout.
  2. Move your mouse pointer over the position where you want to drop or move the component:
    • If you point to a grid cell that is already occupied by another component, you cannot move or drop in that position.
      GridBagLayout feedback
    • If you point to a grid cell that is empty, the cell turns dark grey to indicate the valid drop position. The cursor shows the X and Y grid values for the drop position. The first number is the X value, which represents the column, and the second number is the Y value, which represents the row.
      GridBagLayout feedback
    • If you position your cursor on a grid boundary, a yellow bar indicates that a new column or row number will be added.
    • If any new column or row number is being added by your placement, the background color yellow shows on the cursor X/Y indicator and on the column and row labels. Components that are in rows or columns with yellow circles will be updated to reflect the new grid X/Y values.
      GridBagLayout feedback

      GridBagLayout feedback

      GridBagLayout feedback
  3. Click or release your mouse to drop the component in the position that you selected.
Related tasks
Customizing the layout of components in GridBagLayout
Spanning components across GridBagLayout cells

(C) Copyright IBM Corporation 1999, 2004. All Rights Reserved.