Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Layout manager

From Wikipedia, the free encyclopedia

Layout managers aresoftware components used inwidget toolkits which have the ability to lay outgraphical 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 inpixels or common distance units, so a number of popularwidget 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 specialgraphic containers. This is the case inXUL and the.NET Framework widget toolkit (both inWindows Forms and inXAML).
  • Those where the layout behavior is coded in layout managers, that can be applied to any graphic container. This is the case in theSwing widget toolkit that is part of theJava API.

Examples

[edit]

Android have theConstraintLayout.[1]

GTK have theBox[2] andGrid[3] classes.

XUL

[edit]

InXUL, like thevboxArchived 2012-02-24 at theWayback Machine container to stack components on top of each other.

<?xml version="1.0"?><?xml-stylesheet href="chrome://global/skin/" type="text/css"?><windowid="vbox example"title="Example"xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"><vbox><buttonid="yes"label="Yes"/><buttonid="no"label="No"/><buttonid="maybe"label="Maybe"/></vbox></window>

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

XAML

[edit]

TheDockPanel container lays out children components according to theirDock properties.

<Pagexmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"WindowTitle="myDock Panel"><DockPanel><TextBlockDockPanel.Dock="Top">Top1</TextBlock><TextBlockDockPanel.Dock="Top">Top2</TextBlock><TextBlockDockPanel.Dock="Top">Top3</TextBlock><TextBlockDockPanel.Dock="Top">Top4</TextBlock></DockPanel></Page>

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

Java

[edit]

TheFlowLayout 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.

importjavax.swing.JFrame;importjavax.swing.JButton;importjava.awt.FlowLayout;importjava.awt.Container;publicclassExample{privateJFrameframe;publicExample(){frame=newJFrame("FlowLayout Demo");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setLayout(newFlowLayout());frame.add((newJButton("Button 1")));frame.add((newJButton("Button 2")));frame.add((newJButton("Button 3")));frame.add((newJButton("Long-Named Button 4")));frame.add((newJButton("5")));frame.pack();frame.setVisible(true);}publicstaticvoidmain(String[]args){Exampleex=newExample();}}

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

The FlowLayout example

References

[edit]
  1. ^"Build a responsive UI with ConstraintLayout | Views".Android Developers. Google. Retrieved17 December 2024.
  2. ^"Gtk.Box".docs.gtk.org. Retrieved17 December 2024.
  3. ^"Gtk.Grid".docs.gtk.org. Retrieved17 December 2024.

External links

[edit]
Command input
Data input-output
Informational
Containers
Navigational
Specialwindows
Related concepts
Retrieved from "https://en.wikipedia.org/w/index.php?title=Layout_manager&oldid=1304969861"
Categories:
Hidden category:

[8]ページ先頭

©2009-2025 Movatter.jp