Layouts and Containers"

From Documentation
m
Line 108: Line 108:
 
|}
 
|}
 
===Alignment===
 
===Alignment===
*Users are also allowed to specify align and pack for control alignment.
+
*Users are also allowed to specify align and pack to control alignment.
 
{| border="1px" | width="100%" | cellspacing="0"
 
{| border="1px" | width="100%" | cellspacing="0"
 
|-
 
|-
Line 370: Line 370:
  
 
==Columnlayout==
 
==Columnlayout==
[[ZK Component Reference/Layouts/Columnlayout|Columnlayout]] places its child components into multiple columns, and each column could have any number of child components placed vertically with different height (but the same width). Unlike [[ZK Component Reference/Layouts/Portallayout|portallayout]], the user ''cannot'' move the child components to different locations (of course, the application can re-arrange the order anytime it likes).
+
[[ZK Component Reference/Layouts/Columnlayout|Columnlayout]] places its child components into multiple columns while each column allows any numbers of child components placed vertically with different heights (but with the same widths). Unlike [[ZK Component Reference/Layouts/Portallayout|portallayout]], users are''not able'' to move child components to different locations (of course, the application can re-arrange the order anytime it likes).
  
 
{{ZK PE and EE}}
 
{{ZK PE and EE}}
Line 398: Line 398:
  
 
==Portallayout==
 
==Portallayout==
[[ZK Component Reference/Layouts/Portallayout|Portallayout]] places its child components into multiple columns, and each column could have any number of child components placed vertically with different height (but the same width). The user can move any of them to another location he want like a portal.
+
[[ZK Component Reference/Layouts/Portallayout|Portallayout]] places its child components into multiple columns while each column allows any numbers of child components placed vertically with different heights (but with the same widths). Users are also allowed to move any of them to any other location desired like that of a portal.
  
 
{{ZK EE}}
 
{{ZK EE}}
Line 429: Line 429:
  
 
==Tablelayout==
 
==Tablelayout==
[[ZK Component Reference/Layouts/Tablelayout|Tablelayout]] places its child components in a table. The implementation is based on HTML TABLE tag.
+
[[ZK Component Reference/Layouts/Tablelayout|Tablelayout]] places its child components in a table. Ths implementation is based on a HTML TABLE tag.
  
 
{{ZK EE}}
 
{{ZK EE}}
Line 468: Line 468:
  
 
=Containers=
 
=Containers=
Here are a brief introductions. For detailed information and a complete list, please refer to [[ZK Component Reference/Containers|ZK Component Reference: Containers]].
+
This section provides brief introductions for some of the container components in ZK. For detailed information and the complete list of containers, please refer to [[ZK Component Reference/Containers|ZK Component Reference: Containers]].
  
 
==Div and Span==
 
==Div and Span==
[[ZK Component Reference/Containers/Div|Div]] and [[ZK Component Reference/Containers/Span|span]] are the most lightweight containers to group child components. They are the same as HTML DIV and SPAN tags respectively. Div is displayed as block that the following sibling won't be displayed in the same vertical position; as if there is a line break before and after it. On the other hand, span is displayed ''inline'' with siblings (as if no line break in between).
+
[[ZK Component Reference/Containers/Div|Div]] and [[ZK Component Reference/Containers/Span|span]] are the most light-weighted containers to group child components. They are the same as HTML DIV and SPAN tags respectively. Div is displayed as block that the following sibling won't be displayed in the same vertical position; as if there is a line break before and after it. On the other hand, span is displayed ''inline'' with siblings (as if no line break in between).
  
 
{| border="1px" | width="100%" | cellspacing="0"
 
{| border="1px" | width="100%" | cellspacing="0"
Line 490: Line 490:
 
=== Scrolling ===
 
=== Scrolling ===
 
Span:  
 
Span:  
*Span is a inline element, it can't be scrolled.
+
*Span is an inline element that is not scrollable.
 
Div:  
 
Div:  
*You can specify "overflow:auto;" to style for make Div can be scrolled.
+
*To make Div scrollable, specify "overflow:auto;" into "style".
*Due to the height of Div is count on children, it's height will be increased by it's children, you have to specify a fixed height to Div.
+
*The height of Div is dependent on the size of its children, therefore, in order to keep the height of Div constant for the scroll bar to appear, specify a fixed height to Div.
 
{| border="1px" | width="100%" | cellspacing="0"
 
{| border="1px" | width="100%" | cellspacing="0"
 
|-
 
|-
Line 515: Line 515:
  
 
==Window==
 
==Window==
[[ZK Component Reference/Containers/Window|Window]] is a container providing caption, border, overlapped, draggable, closable, sizable, and many other features. Window is also a owner of [[ZK Developer's Reference/UI Composing/ID Space|a ID space]], such that the IDs of its child components won't be conflict with others.
+
[[ZK Component Reference/Containers/Window|Window]] is a container providing caption, border, overlapped, draggable, closable, sizable, and many other features. Window is also the owner of [[ZK Developer's Reference/UI Composing/ID Space|a ID space]], such that the IDs of its child components won't conflict with others (or each other?).
  
 
{| border="1px" | width="100%" | cellspacing="0"
 
{| border="1px" | width="100%" | cellspacing="0"

Revision as of 03:38, 30 June 2011


Layouts and Containers


Layouts are components used to partition the display area it owns into several sub-areas for its child components, while containers group its child components into the display area it owns.

Users are allowed to nest one from another to create desired UI.

Layouts

This section provides brief introductions for some of the layout components in ZK. For detailed information and the complete list of layouts, please refer to ZK Component Reference: Layouts.

Hlayout and Vlayout

Hlayout and Vlayout are simple and light-weighted layout components that arranges its children to be displayed horizontally and vertically respectively. Also, they are easily customizable as they are made up of HTML DIVs.

DrHlayout.png
<hlayout>
  <div width="100px" height="50px" style="background:blue">1</div>
  <div width="80px" height="70px" style="background:yellow">2</div>
</hlayout>
DrVlayout.png
<vlayout>
  <div width="100px" height="50px" style="background:blue">1</div>
  <div width="80px" height="70px" style="background:yellow">2</div>
</vlayout>

Scrolling

  • To make Hlayout and Vlayout scrollable, specify "overflow:auto;" into "style" .
  • The height of Hlayout and Vlayout are dependent on the size of their children, therefore, in order to keep the height of Hlayout and Vlayout constant for the scroll bar to appear, specify a fixed height to Hlayout and Vlayout or place them into a fixed height container, EX: "<window height="100px"...".
DrHlayout scrolling.png
<hlayout width="100px" height="100px" style="border:1px solid black;overflow:auto;">
	<div width="40px" height="150px" style="background:blue;color:white;">1</div>
	<div width="40px" height="150px" style="background:yellow;">2</div>
</hlayout>
DrVlayout scrolling.png
<vlayout width="100px" height="100px" style="border:1px solid black;overflow:auto;">
	<div width="80px" height="80px" style="background:blue;color:white;">1</div>
	<div width="80px" height="80px" style="background:yellow;">2</div>
</vlayout>

Hbox and Vbox

Similar to Hlayout and Vlayout, Hbox and Vbox arranges its children to be displayed horizontally and vertically. However, they do provide more functionalities such as splitter, align and pack, but performance is slower.

DrHbox.png
<hbox>
  <div width="100px" height="50px" style="background:blue">1</div>
  <splitter collapse="before"/>
  <div width="80px" height="70px" style="background:yellow">2</div>
</hbox>
DrVbox.png
<vbox>
  <div width="100px" height="50px" style="background:blue">1</div>
  <splitter collapse="after"/>
  <div width="80px" height="70px" style="background:yellow">2</div>
</vbox>

Scrolling

  • Hbox and Vbox are created by a table, however, HTML tables are not able to show scroll bars, hence, users need to place them in a scrolling container to achieve this.
DrHlayout scrolling.png
<div width="100px" height="100px" style="border:1px solid black;overflow:auto;">
	<hbox>
		<div width="40px" height="150px" style="background:blue;color:white;">1</div>
		<div width="40px" height="150px" style="background:yellow;">2</div>
	</hbox>
</div>
DrVlayout scrolling.png
<div width="100px" height="100px" style="border:1px solid black;overflow:auto;">
	<vbox>
		<div width="80px" height="80px" style="background:blue;color:white;">1</div>
		<div width="80px" height="80px" style="background:yellow;">2</div>
	</vbox>
</div>

Alignment

  • Users are also allowed to specify align and pack to control alignment.
DrHbox align.png
<window title="Hbox" border="normal" width="150px" height="100px">
	<caption label="align: center" />
	<hbox width="100%" height="100%" style="border:1px solid black;"
		align="center">
		<button label="1" />
		<button label="2" />
	</hbox>
</window>
DrHbox pack.png
<window title="Hbox" border="normal" width="150px" height="100px">
	<caption label="pack: center" />
	<hbox width="100%" height="100%" style="border:1px solid black;" 
		pack="center">
		<button label="1" />
		<button label="2" />
	</hbox>
</window>
DrVbox align.png
<window title="Vbox" border="normal" width="150px" height="150px">
	<caption label="align: center" />
	<vbox width="100%" height="100%" style="border:1px solid black;" 
		align="center">
		<button label="1" />
		<button label="2" />
	</vbox>
</window>
DrVbox pack.png
<window title="Vbox" border="normal" width="150px" height="150px">
	<caption label="pack: center" />
	<vbox width="100%" height="100%" style="border:1px solid black;" 
		pack="center">
		<button label="1" />
		<button label="2" />
	</vbox>
</window>

For more detailed information, please refer to Hbox and Vbox.

  • Users are also allowed to use "cell" to control each cell's alignment.
DrHbox Cell.png
<hbox width="500px">
	<cell style="border:1px solid black;">
		<button label="Help"/>
	</cell>
	<cell style="border:1px solid black;"
		hflex="6" align="center">
		<button label="Add"/>
		<button label="Reomve"/>
		<button label="Update"/>
	</cell>
	<cell style="border:1px solid black;"
		hflex="4" align="right">
		<button label="OK"/>
		<button label="Cancel"/>
	</cell>
</hbox>
DrVbox Cell.png
<vbox width="300px" align="stretch">
	<cell style="border:1px solid black;">
		<button label="Help"/>
	</cell>
	<cell style="border:1px solid black;"
		align="center">
		<button label="Add"/>
		<button label="Reomve"/>
		<button label="Update"/>
	</cell>
	<cell style="border:1px solid black;"
		align="right">
		<button label="OK"/>
		<button label="Cancel"/>
	</cell>
</vbox>

Borderlayout

Borderlayout places its child components in up to five areas: north, east, south, west and center. All extra space is placed in the center area.

DrBorderlayout.png
<borderlayout width="100px" height="100px">
	<north>
		<div style="background:#008db7;color:white;">N</div>
	</north>
	<south>
		<div style="background:#112f37;color:white;">S</div>
	</south>
	<center>
		<div>C</div>
	</center>
	<east>
		<div style="background:#f2f2f2;">E</div>
	</east>
	<west>
		<div style="background:#f2f2f2;">W</div>
	</west>
</borderlayout>

flex

Layout region will share the height of Borderlayout, the sequence is North, South, Center, and the height of East and West is count on Center, in the previous sample, the div in the layout region will not take whole of the layout region's space , you have to specify flex="true" to the layout region, let the child to occupy whole space.

DrBorderlayout flex.png
<borderlayout width="100px" height="100px">
	<north>
		<div style="background:#008db7;color:white;">N</div>
	</north>
	<south>
		<div style="background:#112f37;color:white;">S</div>
	</south>
	<center>
		<div>C</div>
	</center>
	<east flex="true">
		<div style="background:#f2f2f2;">E</div>
	</east>
	<west flex="true">
		<div style="background:#f2f2f2;">W</div>
	</west>
</borderlayout>

Scrolling

  • The height of Center will count on Borderlayout not count on child, so Center's height will not grow by child component, if Center's height is not enough for it's child, Center will cut the content of it's child, you have to specify autoscroll="true" to Center, let Center to handle the scrolling.
DrBorderlayout Center scrolling.png
<borderlayout width="300px" height="300px">
	<north>
		<div height="100px"  style="background:#008db7;color:white;">N</div>
	</north>
	<south>
		<div height="100px"  style="background:#112f37;color:white;">S</div>
	</south>
	<center autoscroll="true">
		<div height="200px">C</div>
	</center>
	<east flex="true">
		<div width="30px" style="background:#f2f2f2;">E</div>
	</east>
	<west flex="true">
		<div width="20px" style="background:#f2f2f2;">W</div>
	</west>
</borderlayout>

Grow by children

  • If you want Borderlayout grow by children, you have to use vflex feature, specify vflex="min" to each layout region and Borderlayout.
DrBorderlayout grow.png
<borderlayout width="300px" vflex="min">
	<north vflex="min">
		<div height="100px"  style="background:#008db7;color:white;">N</div>
	</north>
	<south vflex="min">
		<div height="100px"  style="background:#112f37;color:white;">S</div>
	</south>
	<center vflex="min">
		<div height="200px">C</div>
	</center>
	<east flex="true">
		<div width="30px" style="background:#f2f2f2;">E</div>
	</east>
	<west flex="true">
		<div width="20px" style="background:#f2f2f2;">W</div>
	</west>
</borderlayout>

Borderlayout in a container

  • Almost of container's height is count on children, place Borderlayout in a container, you have to specify a height to Borderlayout.
<zk>
	<window title="win" border="normal">
		<borderlayout height="200px">
			<north>
				<div style="background:blue">N</div>
			</north>
			<south>
				<div style="background:blue">S</div>
			</south>
			<center>
				<div>C</div>
			</center>
			<east>
				<div style="background:yellow">E</div>
			</east>
			<west>
				<div style="background:yellow">W</div>
			</west>
		</borderlayout>
	</window>
</zk>
  • The default height of Borderlayout is count on parent component, you can put Borderlayout in a fixed height container.
<zk>
	<window title="win" border="normal" height="200px">
		<borderlayout>
			<north>
				<div style="background:blue">N</div>
			</north>
			<south>
				<div style="background:blue">S</div>
			</south>
			<center>
				<div>C</div>
			</center>
			<east>
				<div style="background:yellow">E</div>
			</east>
			<west>
				<div style="background:yellow">W</div>
			</west>
		</borderlayout>
	</window>
</zk>

Columnlayout

Columnlayout places its child components into multiple columns while each column allows any numbers of child components placed vertically with different heights (but with the same widths). Unlike portallayout, users arenot able to move child components to different locations (of course, the application can re-arrange the order anytime it likes).

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion pe-ee.png
DrColumnlayout.png
<columnlayout>
  <columnchildren width="30%" style="padding: 5px 1px">
    <panel height="60px" title="1" border="normal" maximizable="true">
      <panelchildren>1</panelchildren>
    </panel>
    <panel height="80px" title="2" border="normal" closable="true">
      <panelchildren>2</panelchildren>
    </panel>
  </columnchildren>
  <columnchildren width="70%" style="padding: 5px 1px">
    <panel height="100px" title="3" border="normal" collapsible="true">
      <panelchildren>3</panelchildren>
    </panel>
  </columnchildren>
</columnlayout>

Portallayout

Portallayout places its child components into multiple columns while each column allows any numbers of child components placed vertically with different heights (but with the same widths). Users are also allowed to move any of them to any other location desired like that of a portal.

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png
DrPortallayout.png
<portallayout>
  <portalchildren width="40%" style="padding: 5px 1px">
    <panel height="60px" title="1" border="normal" maximizable="true">
      <panelchildren>1</panelchildren>
    </panel>
    <panel height="90px" title="2" border="normal" closable="true">
      <panelchildren>2</panelchildren>
    </panel>
  </portalchildren>
  <portalchildren width="60%" style="padding: 5px 1px">
    <panel height="100px" title="3" border="normal" collapsible="true">
      <panelchildren>3</panelchildren>
    </panel>
    <panel height="55px" title="4" border="normal" closable="true">
      <panelchildren>4</panelchildren>
    </panel>
  </portalchildren>
</portallayout>

Tablelayout

Tablelayout places its child components in a table. Ths implementation is based on a HTML TABLE tag.

  • Available for ZK:
  • http://www.zkoss.org/product/zkhttp://www.zkoss.org/whyzk/zkeeVersion ee.png
DrTablelayout.png
<tablelayout columns="2">
  <tablechildren>
    <panel title="1" border="normal"
      collapsible="true" width="80px" height="60px">
      <panelchildren>1</panelchildren>
    </panel>
  </tablechildren>
  <tablechildren>
    <panel title="2" border="normal"
      collapsible="true" width="80px" height="60px">
      <panelchildren>2</panelchildren>
    </panel>
  </tablechildren>
  <tablechildren>
    <panel title="3" border="normal"
      collapsible="true" width="80px" height="60px">
      <panelchildren>3</panelchildren>
    </panel>
  </tablechildren>
  <tablechildren>
    <panel title="4" border="normal"
      collapsible="true" width="80px" height="60px">
      <panelchildren>4</panelchildren>
    </panel>
  </tablechildren>
</tablelayout>

Containers

This section provides brief introductions for some of the container components in ZK. For detailed information and the complete list of containers, please refer to ZK Component Reference: Containers.

Div and Span

Div and span are the most light-weighted containers to group child components. They are the same as HTML DIV and SPAN tags respectively. Div is displayed as block that the following sibling won't be displayed in the same vertical position; as if there is a line break before and after it. On the other hand, span is displayed inline with siblings (as if no line break in between).

DrDivSpan.png
<div style="border: 1px solid blue" width="150px">
  this is
  <span>inlined with <button label="Hi"/></span>
</div>
<div style="border: 1px solid grey">
	<div>div is a block</div>
	<datebox/>
</div>

Scrolling

Span:

  • Span is an inline element that is not scrollable.

Div:

  • To make Div scrollable, specify "overflow:auto;" into "style".
  • The height of Div is dependent on the size of its children, therefore, in order to keep the height of Div constant for the scroll bar to appear, specify a fixed height to Div.
DrDiv scrolling.png
<div height="100px" width="100px" 
	style="border:1px solid black;overflow:auto;">
	<grid>
		<rows>
			<row>item</row>
			<row>item</row>
			<row>item</row>
			<row>item</row>
			<row>item</row>
		</rows>
	</grid>
</div>

Window

Window is a container providing caption, border, overlapped, draggable, closable, sizable, and many other features. Window is also the owner of a ID space, such that the IDs of its child components won't conflict with others (or each other?).

DrWindow.png
<window title="A" closable="true" sizable="true"
 border="normal" mode="overlapped">
   <div style="background: yellow">1</div>
   <combobox/>
</window>

Scrolling

  • You can specify "overflow:auto;" to contentStyle for make Window can be scrolled.
  • Due to the height of Window is count on children, it's height will be increased by it's children, you have to specify a fixed height to Window.
DrWindow scrolling.png
<window title="window" border="normal" 
	height="150px" width="150px"
	contentStyle="overflow:auto;">
	<grid>
		<rows>
			<row>item</row>
			<row>item</row>
			<row>item</row>
			<row>item</row>
			<row>item</row>
		</rows>
	</grid>
</window>

Panel

Like Window, panel is another powerful container, supporting caption, border, overlapped and many other features. However, it does not implement IdSpace, so all of its children belongs to the same ID space of its parent.

DrPanel.png
<panel title="A" framable="true" border="normal"
 maximizable="true" collapsible="true">
   <panelchildren>
      <div style="background: yellow">1</div>
      <combobox/>
   </panelchildren>
</panel>

Scrolling

  • You can specify "overflow:auto;" to style of Panelchildren for make Panel can be scrolled.
  • Due to the height of Panel is count on children, it's height will be increased by it's children, you have to specify a fixed height to Panel.
DrPanel scrolling.png
<panel title="panel" border="normal" 
	height="150px" width="150px">
	<panelchildren style="overflow:auto;">
		<grid>
			<rows>
				<row>item</row>
				<row>item</row>
				<row>item</row>
				<row>item</row>
				<row>item</row>
			</rows>
		</grid>
	</panelchildren>
</panel>

Groupbox

Groupbox is a lightweight way to group child components. It supports the caption and border, but it can not be overlapped or sized. It does not implement IdSpace either.

DrGroupbox3d.png
<groupbox mold="3d">
  <caption label="Fruits"/>
  <radiogroup>
    <radio label="Apple"/>
    <radio label="Orange"/>
    <radio label="Banana"/>
  </radiogroup>
</groupbox>

Scrolling

3d mold only
  • You can specify "overflow:auto;" to contentStyle for make Groupbox can be scrolled.
  • Due to the height of Groupbox is count on children, it's height will be increased by it's children, you have to specify a fixed height to Groupbox.
DrGroupbox3d scrolling.png
<groupbox mold="3d" height="150px" width="150px"
	contentStyle="overflow:auto;">
	<caption label="3d groupbox" />
	<grid>
		<rows>
			<row forEach="1,2,3,4,5,6">item</row>
		</rows>
	</grid>
</groupbox>

Tabbox

Tabbox is a container used to display a set of tabbed groups of components. A row of tabs is displayed at the top (or left or other location) of tabbox which may be used to switch between each group. It does not implement IdSpace either.

DrTabbox.png
<tabbox height="80px">
  <tabs>
    <tab label="Tab 1"/>
    <tab label="Tab 2"/>
  </tabs>
  <tabpanels>
    <tabpanel>This is panel 1</tabpanel>
    <tabpanel>This is panel 2</tabpanel>
  </tabpanels>
</tabbox>

Scrolling

  • You can specify "overflow:auto;" to style of Tabpanel for make Tabpanel can be scrolled.
  • Due to the height of Tabpanel is count on children, it's height will be increased by it's children, you have to specify a fixed height to Tabbox.
DrTabbox scrolling.png
<tabbox height="100px" width="150px">
	<tabs>
		<tab label="tab" />
	</tabs>
	<tabpanels>
		<tabpanel style="overflow:auto;">
			<grid>
				<rows>
					<row forEach="1,2,3,4,5,6">item</row>
				</rows>
			</grid>
		</tabpanel>
	</tabpanels>
</tabbox>

Version History

Last Update : 2011/06/30


Version Date Content
     



Last Update : 2011/06/30

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.