fbpx
Wikipedia

Layout manager

Layout managers are software components used in widget toolkits which have the ability to lay out graphical control elements by their relative positions without using distance units. It is often more natural to define component 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:

  • Those where the layout behavior is coded in special graphic containers. This is the case in XUL and the .NET Framework widget toolkit (both in Windows Forms and in XAML).
  • Those where the layout behavior is coded in layout managers, that can be applied to any graphic container. This is the case in the Swing widget toolkit that is part of the Java API.

Examples edit

XUL edit

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"  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <vbox>  <button id="yes" label="Yes"/>  <button id="no" label="No"/>  <button id="maybe" label="Maybe"/> </vbox> </window> 

This piece of code shows 3 buttons stacked on top of each other in a vertical box.

XAML edit

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

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   WindowTitle="myDock Panel">  <DockPanel>  <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>  </DockPanel> </Page> 

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

Java edit

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.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  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")));  frame.pack();  frame.setVisible(true);  }  public static void main(String[] args) {  Example ex = new Example();  } } 

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

 

External links edit

  • Layout tutorial on Oracle website

layout, manager, software, components, used, widget, toolkits, which, have, ability, graphical, control, elements, their, relative, positions, without, using, distance, units, often, more, natural, define, component, layouts, this, manner, than, define, their,. Layout managers are software components used in widget toolkits which have the ability to lay out graphical control elements by their relative positions without using distance units It is often more natural to define component 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 Those where the layout behavior is coded in special graphic containers This is the case in XUL and the NET Framework widget toolkit both in Windows Forms and in XAML Those where the layout behavior is coded in layout managers that can be applied to any graphic container This is the case in the Swing widget toolkit that is part of the Java API Contents 1 Examples 1 1 XUL 1 2 XAML 1 3 Java 2 External linksExamples editXUL edit In XUL like the vbox container to stack components on top of each other lt xml version 1 0 gt lt xml stylesheet href chrome global skin type text css gt lt window id vbox example title Example xmlns http www mozilla org keymaster gatekeeper there is only xul gt lt vbox gt lt button id yes label Yes gt lt button id no label No gt lt button id maybe label Maybe gt lt vbox gt lt window gt This piece of code shows 3 buttons stacked on top of each other in a vertical box XAML edit The DockPanel container lays out children components according to their Dock properties lt Page xmlns http schemas microsoft com winfx 2006 xaml presentation WindowTitle myDock Panel gt lt DockPanel gt lt TextBlock DockPanel Dock Top gt Top 1 lt TextBlock gt lt TextBlock DockPanel Dock Top gt Top 2 lt TextBlock gt lt TextBlock DockPanel Dock Top gt Top 3 lt TextBlock gt lt TextBlock DockPanel Dock Top gt Top 4 lt TextBlock gt lt DockPanel gt lt Page gt This code shows 4 text blocks on top of each other Java edit 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 setDefaultCloseOperation JFrame EXIT ON CLOSE 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 frame pack frame setVisible true public static void main String args Example ex new Example This code shows 5 buttons alongside each other on the same line nbsp External links editLayout tutorial on Oracle website Layout Manager Showdown on java net Retrieved from https en wikipedia org w index php title Layout manager amp oldid 1209896401, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.