Layout manager

Layout managers are software components used in widget toolkits which have the ability to layouts in this manner than to define their position in pixels or common distance units, so a number of popular widget toolkits include this ability by default. Widget toolkits that provide this function can generally be classified into two groups:



In XUL, like the vbox container to stack components on top of each other.

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="vbox example" title="Example"

  <button id="yes" label="Yes"/>
  <button id="no" label="No"/>
  <button id="maybe" label="Maybe"/>


This piece of code shows 3 buttons stacked on top of each other in a vertical box: history plans for future vfx video film ads film


The DockPanel container lays out children components according to their Dock properties.

<Page xmlns="" 
      WindowTitle="myDock Panel">
      <TextBlock DockPanel.Dock="Top">Top 1</TextBlock>
      <TextBlock DockPanel.Dock="Top">Top 2</TextBlock>
      <TextBlock DockPanel.Dock="Top">Top 3</TextBlock>
      <TextBlock DockPanel.Dock="Top">Top 4</TextBlock>

This code shows 4 text blocks on top of each other.


The FlowLayout layout manager arranges components in a directional flow, much like lines of text in a paragraph. It arranges components horizontally until no more components fit on the same line, then it places them on another line. Other layout managers are GridLayout managers which arrange the components in grid form and BorderLayout managers which also arranges the component in five parts of the frame,thus: south,north, west,east and center.

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.Container;

public class Example {
    private JFrame frame;

    public Example() {
        frame = new JFrame("FlowLayout Demo");
        frame.setLayout(new FlowLayout());
        frame.add((new JButton("Button 1")));
        frame.add((new JButton("Button 2")));
        frame.add((new JButton("Button 3")));
        frame.add((new JButton("Long-Named Button 4")));
        frame.add((new JButton("5")));

    public static void main(String[] args) {
        Example ex = new Example();

This code shows 5 buttons alongside each other on the same line:

External links

This article is issued from Wikipedia - version of the 9/2/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.