Swing GridBagLayout

The GridBagLayout class is a flexible layout manager that aligns components vertically, horizontally or along their baseline without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying one or more cells, called its display area. Each component managed by a GridBagLayout is associated with an instance of GridBagConstraints. The constraints object specifies where a component's display area should be located on the grid and how the component should be positioned within its display area. In addition to its constraints object, the GridBagLayout also considers each component's minimum and preferred sizes in order to determine a component's size.

Play movie. Requires a web connection.
Play Movie

Main Features

  • Select GridBagLayout from the Swing Layouts palette and drop it on a JFrame or JPanel

  • Graphical feedback is provided for all column, row and cell interactions
  • Cell properties within a column or row may be changed via a popup menu

Popup Header Menu

  • Right-click on the header area to access the popup header menu
        
  • Set the cell anchor position
  • Specify that the column or row should fill the cell

Graphical Feedback

  • When moving a widget or adding a new widget, open cells are highlighted

      
     
  • Insertion drop point between the current cells will create new columns and rows as needed

      
  • The currently selected cell shows its column and row spanning handles, inset handles, sizing handles and alignment handles

  • Set the fill properties of a cell using its fill toggle

  

  • Set the anchor of a cell by dragging within the cell

  

  • Right-click (or double-click) on a column to set its grab property

  

  

  • Width and height sizing handles make it easy to set the size of a widget

  

  • Reorder columns and rows by dragging them

  

  • Column and rows borders are indicated with dotted lines

  • Interactive column and row spanning feedback is provided

  

  • Column and row weight handles make it easy to set the size of a column or row.
    The green column and row numbers indicate the weight

  

  

Cell Editing

  • Floating layout assistant for cells


Preferences & Options

  • Control the style of code generation (empty constructor or full constructor)
  • Control which handles are shown (spanning, inset and fill)
  • Control the default insets used when creating controls