Layout manager

from Wikipedia, the free encyclopedia

Layout Manager referred to in the programming software component that is the arrangement of controls in a parent container (eg. As a window cares). Each element is not assigned a position and size using pixel coordinates , but the layout manager has a defined set of rules as to how the elements should be arranged. The most important advantage of layout managers compared to absolute positioning is the independence of font and window sizes.

Layout managers are usually part of a GUI toolkit .

Layout manager in Java

Examples

Layout nesting
  • BorderLayout
  • BoxLayout
  • CardLayout
  • FlowLayout (enabled by default)
  • GridBagLayout
  • GridLayout
  • OverlayLayout
  • SpringLayout

FlowLayout

With the FlowLayout activated by default, the components are simply arranged one behind the other in the order in which they were inserted on the panel. When the end of the frame is reached, a line break is created.

BorderLayout

The BorderLayout will be described as an example. Five components can be arranged in a BorderLayout. The five components can be assigned the "direction" as arrangement rules: NORTH, EAST, SOUTH, WEST and CENTER. The following graphic shows where the components are located (please note: a LayoutManager never shows lines, borders or frames; the lines shown here only serve to clarify the boundaries of the individual components):

Representation of the border layout

Usually, containers with additional components and individual layouts are arranged in a BorderLayout. For example, it often happens that you want EAST and WEST NORTH and SOUTH superordinate, so that EAST and WEST extend over the full height and NORTH and SOUTH do not have the full width, but the width of CENTER. This can be easily implemented by leaving NORTH and SOUTH empty in the outer BorderLayout, but filling CENTER again with a BorderLayout, in which you can now adjust NORTH and SOUTH.

For example, a panel (container for GUI components) would be created in the NORTH area with a FlowLayout in order to create toolbar buttons there if necessary. A panel is created in the SOUTH area (also with a FlowLayout, but right-justified), for example to create an OK and Cancel button . The CENTER area is used with a panel with GridBagLayout for input elements. The WEST and EAST areas could be left unoccupied. The LayoutManager would let the component in the CENTER area expand to the right and left to the edge.

See also