Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

This section introduces the layout manager.

  1. What is Nexaweb layout manager
  2. A visual guide to layout managers
  3. Where to use layout managers
  4. How to use Nexaweb layout managers

What is Nexaweb Layout Manager?

Nexaweb Layout Manager is very similar to layout managers that the Java platform provides. 
Nexaweb layout managers control the position of child components in a container. (A container is a UI element in a Nexaweb application that can hold child components and to which you may add layout managers and other visual elements (including both containers and components) in order to create the application’s visual appearance.)
Different layout managers provide different resizing behaviors. The predefined Nexaweb layout managers include:
  • BorderLayout 
  • BoxLayout 
  • CardLayout 
  • FlowLayout 
  • FreeLayout 
  • GridLayout
You can use one layout manager or combine several of them in the same container to achieve the UI design you desire. Each layout manager has its own special attributes
that you can set to achieve different layout results.  You can also assign generic attributes to child components - for example, margin and layout manager specific attributes such as hAlign for gridLayout, flex for boxLayout - to assist layout managers to create the layout that you want. If you do not specify a layout manager, Nexaweb Studio uses flowLayout - the simplest layout manager, that arranges components horizontally or vertically in the order in which you place them within the container - as the default. If a predefined layout cannot satisfy your needs, you can create a customized layout.  See Plugin-in documentation for more details.
 
The quickest way for you to get your application to look the way you want is to learn how the layout managers work. For an example of the different layout managers either import into Studio (Using Eclipse’s Import wizard) or build and deploy the Sample Explorer part of the samples included in the Nexaweb Platform 4.0 installation.

...

Image Removed

...

ここでは、レイアウト マネージャについて説明します。
  1. Nexaweb レイアウト マネージャとは
  2. レイアウト マネージャの図解入り解説
  3. レイアウト マネージャを使用する場合
  4. Nexaweb レイアウト マネージャの使用方法

Nexaweb レイアウトマネージャとは

Nexaweb レイアウト マネージャは、Java プラットフォームで使用可能なレイアウト マネージャと非常に似ています。
Nexaweb レイアウト マネージャは、コンテナ内で子コンポーネントの位置を制御します。(コンテナは Nexaweb アプリケーションの UI 要素で、子コンポーネントを保持できます。また、アプリケーションの外観を作成するために、レイアウト マネージャやその他の視覚的要素 (コンテナやコンポーネントを含む) を追加することができます。)
レイアウト マネージャの種類によって、サイズ変更時の動作は異なります。定義済みの Nexaweb レイアウト マネージャには次の種類があります。
  • BorderLayout
  • BoxLayout
  • CardLayout
  • FlowLayout
  • FreeLayout
  • GridLayout
ニーズに合った UI デザインを実現するために、1 種類のレイアウト マネージャを使用することも、複数のレイアウト マネージャを同じコンテナ内で組み合わせて使用することもできます。また、各レイアウト マネージャには独自の特殊属性が用意されており、それらの属性を設定することによってさまざまなレイアウト結果を得ることができます。
また、汎用的な属性を子コンポーネントに割り当てて、レイアウト マネージャで目的のレイアウトを作成することも可能です。たとえば、マージンに関する属性やレイアウト マネージャ固有の属性 (gridLayout の hAlign、boxLayout の flex など) があります。レイアウト マネージャを指定しない場合は、Nexaweb Studio のデフォルト設定により flowLayout が使用されます。この最もシンプルなレイアウト マネージャを使用すると、コンポーネントが、コンテナ内に配置する順序に従って水平方向または垂直方向に並べられます。定義済みのレイアウトがニーズを十 分に満たさない場合は、カスタムのレイアウトを作成できます。詳細については、プラグインのドキュメントを参照してください。
 
アプリケーションの外観を意図したとおりに作成するためには、レイア ウト マネージャの仕組みを習得することが一番の早道です。各種レイアウト マネージャのサンプルを使用するには、Eclipse のインポート ウィザードを使用して Studio にレイアウト マネージャをインポートするか、Nexaweb Platform 4.0 のインストール プログラムに含まれているサンプルの Sample Explorer をデプロイします。

レイアウトマネージャの図解入り解説


BorderLayout
BorderLayout は、最大 5 つまでの領域 (north、south、west、east、center) にコンポーネントを配置します。north と south に配置されるコンポーネントは水平方向に、west と east に配置されるコンポーネントは垂直方向に広がって配置されます。center に配置されるコンポーネントは両方向に広がり、残りのスペースは中央のコンポーネントで占められます。コンポーネントの属性 borderPosition を指定すると、子コンポーネントをこれらの領域に配置できます。borderPosition 属性の値には、各領域に対応する north、west、center、east、south を選択できます。次の XML コードの例は、上のウィンドウを表しています。
Code Block
<window title="window" width="350" height="200">
    <borderLayout/>
    <button borderPosition="north" text="North"/> 
    <button borderPosition="west" text="West"/>
    <button borderPosition="center" text="Center"/>
    <button borderPosition="east" text="East"/>
    <button borderPosition="south" text="South"/>
</window>

As this example shows, child components expand themselves to fill the area in which they reside.  If you resize the window, the components resize themselves as well to fill the area.  BorderLayout ignores the size of component placed in the center area so that the component can fill any available space.  Components placed in north and south maintain their height as Components placed in west and east maintain their width.

You don't have to put components to all 5 areas.  In fact, it is quite common that 2 or 3 areas are enough to get the layout result you want.

BoxLayout

Image Removed

...

 
 
こ の例に示すように、子コンポーネントのサイズは、子コンポーネントが配置される領域の大きさに応じて拡大されます。ウィンドウのサイズを変更すると、その 領域を占めるコンポーネントのサイズも変更されます。BorderLayout では、center 領域に配置されたコンポーネントのサイズは無視され、すべての使用可能領域がそのコンポーネントによって占められます。north と south に配置されたコンポーネントではその高さが保持され、west と east に配置されたコンポーネントではその幅が保持されます。

5 つの領域すべてにコンポーネントを配置する必要はありません。実際、2 つか 3 つの領域を使用するだけで目的のレイアウト結果が得られる場合もよくあります。
BoxLayout

BoxLayout は、orientation 属性で指定する方向に従って、コンポーネントを 1 つの行または列に配置します。コンポーネントのサイズがコンテナのサイズより大きい場合、コンポーネントは次の行または列に折り返されません。これに対 し、flowLayout では、使用可能なスペースにコンポーネントが折り返されます。BoxLayout のデフォルト設定ではコンポーネントのサイズが優先されるため、コンテナのサイズが変化しても、コンポーネントのサイズは変更されません。次の XML コードの例は、上のウィンドウを表しています。

Code Block
<window title="window" width="350" height="200" margin="5">
    <boxLayout orientation="vertical"/>
    <button text="button 1"/>
    <button text="button 2 - wide"/>
    <textField />
    <comboBox />  
    <radioButton text="radio button" />
</window> 

...

 

...

 

Image Removed

CardLayout allows you to put different components to a common container, while showing only one of them at a time as you specify with the show attribute.  The displayed component occupies the entire space of its parent container. The best example of a cardLayout is a slideshow. As shown in the windows above, clicking Card 1 or Card 2 button sets the show attribute of cardLayout and makes the corresponding component in the deck show up. The following example xml represents the windows shown above:

...

languagehtml/xml
linenumberstrue

...

CardLayout
CardLayout を使用すると、複数のコンポーネントを共通のコンテナに配置できます。show 属性を使用して指定すると、コンポーネントが一度に 1 つだけ表示されます。表示されるコンポーネントは、その親コンテナのスペース全体を占めます。CardLayout の最もわかりやすい例はスライドショーです。上のウィンドウで示されているように、Card 1 または Card 2 ボタンをクリックすると、CardLayout の show 属性が設定され、スライド一式の中にある対応するコンポーネントが表示されます。次の XML コードの例は、上のウィンドウを表しています。
Code Block
 <nxml>
    <macro:macro xmlns:macro="http://nexaweb.com/macro" name="showCard1">
        <xu:modifications xmlns:xu="http://nexaweb.com/xupdate">
            <xu:set-attribute select="//cardLayout">
                <xu:attribute name="show" value="card1"/>
            </xu:set-attribute>
        </xu:modifications>
    </macro:macro>
    <macro:macro xmlns:macro="http://nexaweb.com/macro" name="showCard2">
        <xu:modifications xmlns:xu="http://nexaweb.com/xupdate">
            <xu:set-attribute select="//cardLayout">
                <xu:attribute name="show" value="card2"/>
            </xu:set-attribute>
        </xu:modifications>
    </macro:macro>
    <window height="200" title="Window" width="400" >
        <borderLayout gapVertical="5"/>
        <panel height="40" width="100" borderPosition="south" bgColor="#808080">
            <flowLayout bgColoralign="#808080center"/>
      <flowLayout align="center"/>
      <button text="Card 1" onCommand="macro://showCard1"/>
            <button text="Card 2" onCommand="macro://showCard2"/>
        </panel>
        <panel height="100" width="100" borderPosition="center" bgColor="#008000">
            bgColor<cardLayout show="#008000card2"/>
      <cardLayout show="card2"/>
      <label height="20" text="Card 1" width="100" alignHorizontal="center"
                  alignHorizontal="center" alignVertical="center" 
             fontBold="true" fontSize="100" name="card1"/>
            <label height="20" text="Card 2" width="100" alignHorizontal="center" 
            alignHorizontal="center" alignVertical="center"               alignVertical="center" fontBold="true" fontSize="100" name="card2"/>
        </panel>
   </window>
</nxml> 

...

 

...


FlowLayout
FlowLayout

...

はデフォルトのレイアウトマネージャで、他のレイアウトマネージャを指定しない場合は、Nexaweb Studio ですべてのコンテナに使用されます。FlowLayout は、各コンポーネントに指定した位置とサイズに応じて、コンポーネントを 1 つの行または列に配置します。コンポーネントのコンテナの幅や高さが足りない場合は、新しい行または列を開始します。次の XML コードの例は、上のウィンドウを表しています。
Code Block
 <window title="window" width="350" height="200">
    <flowLayout/>
    <button text="button 1"/>
    <textField />
    <comboBox />
    <radioButton text="radio button" />
</window>

FreeLayout

Image Removed

FreeLayout arranges components according to the absolute sizes and positions that you specify for each component.  When sizing and positioning components, you need to consider that screen size may vary from one computer to another. Use FreeLayout when other layout managers cannot meet your requirements or when you want to add components to the container with x/y coordinates from a mouse event. The following example xml represents the window shown above:

...


FreeLayout は、各コンポーネントに指定した絶対的なサイズと位置に応じて、コンポーネントを配置します。コンポーネントのサイズや位置を決める場合は、画面のサイズ がコンピュータによって異なることを考慮する必要があります。他のレイアウトマネージャで必要なレイアウトが作成できない場合や、マウスイベントから x/y 座標を使用してコンポーネントをコンテナに追加する場合にFreeLayout を使用します。次の XML コードの例は、上のウィンドウを表しています。
Code Block
<window height="200" title="Window" width="400">
 	    <freeLayout/>
 	    <button  text="Button"  x="60" y="29"/>

	    <textField text="TextField" x="220" y="59"/>

	    <comboBox x="40" y="79"/>

	    <radioButton text="radioButton" x="100" y="119"/>

	    <link text="link" x="190" y="159"/>

	    <label text="label" x="250" y="109"/>

</window> 
 
GridLayout

Image Removed
 
GridLayout arranges components row by row in a uniform grid, based on the order in which you add components to the parent container. GridLayout sizes each component the same and the overall grid will exactly fit the parent container. You specify the number of columns in the grid through the columns attribute.  In addition to the GridLayout attributes, you can use child component attributes to help sizing and placing child components in the grid. The following example xml represents the window shown above:

...

Image AddedImage Added

GridLayout は、コンポーネントを親コンテナに追加する順序に基づいて、同じサイズのグリッド内に、行ごとに 1 つずつ配置します。各コンポーネントのサイズは同じになり、グリッド全体は親コンテナに完全に適合します。グリッドの列数は、columns 属性を使用して指定します。グリッド内の子コンポーネントのサイズや位置を決める場合は、GridLayout 属性に加えて、子コンポーネントの属性を使用できます。次の XML コードの例は、上のウィンドウを表しています。

 

Code Block
<window height="180" title="Window" width="350">
    <gridLayout columns="3"/>
    <button  text="Button"/>
    <link text="link"/>
    <comboBox/>
    <radioButton text="radioButton"/>
    <textField text="TextField"/>
    <button  text="Button"/>
    <listBox>
        <listItem text="listItem 1"/>
        <listItem text="listItem 2"/>
    </listBox>
    <button text="Button"/>
</window>

...


GridLayout

...

は SWT グリッドレイアウトの後で形成されます - http://www.eclipse.org/articles/Understanding%20Layouts/Understanding%20Layouts.htm

...

レイアウトマネージャはどこで使用するのか?

...

それぞれのコンテナ状コンポーネント(panel, desktopPane, rootPane, window, dialog)

...

は子コンポーネントをレイアウトするためにレイアウトマネージャが必要です。ただし、次の特別コンポーネントは除きます :

  • scrollPane
  • tabPane

...

  • とその子コンポーネント tab
  • splitPane

...

  • とその4つの子コンポーネント (top | bottom | letf | roght)

(未完成)