Layoutmanager

Layout Manager referred to in the programming elements that is the arrangement of visual components in a parent container (eg a window ) themselves. Each component is not positioned a position and size using pixel coordinates, but the layout manager has a defined set of rules of how the components are to be arranged. The most important advantage of layout managers in relation to the absolute positioning is the independence of font and window sizes.

Layout Manager in Java

Examples

  • BorderLayout
  • BoxLayout
  • CardLayout
  • FlowLayout ( Enabled by default )
  • GridBagLayout
  • GridLayout
  • Overlay layout
  • Spring layout

FlowLayout

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

BorderLayout

As an example, the BorderLayout will be described. In a BorderLayout five components can be placed. When ordering rules can be given to the five components of the " direction ": NORTH, EAST, SOUTH, WEST and CENTER. The following graphic illustrates where the components are then (please note that a layout manager never shows lines, borders or frames on, the lines are only shown here to illustrate the limits of the individual components):

Usually, arranged in a border layout in container with other components and individual layouts. So it comes as frequently happens that one EAST and WEST NORTH SOUTH and wants to have the parent, so that EAST and WEST extend the full height and not get NORTH and SOUTH the full width, but the width of CENTER. This can be realized simply by completely empty can in the outer BorderLayout NORTH and SOUTH, CENTER but again filled with a Border layout now while you can customize NORTH and SOUTH.

For example, you would create a panel (container for GUI components ) in the NORTH area with a FlowLayout to there, where appropriate, to create toolbar buttons. In the SOUTH area you put a panel on (also with a FlowLayout, but with right alignment ), for example, to create an OK and Cancel button. The CENTER - range one uses a panel with GridBagLayout for input elements. The areas WEST and EAST might be unoccupied. The layout manager would leave the component in the CENTER area to the right and left fully extended.

  • Graphical User Interface
502026
de