Layout Manager - NXML
- Nexaweb レイアウト マネージャとは
- レイアウト マネージャの図解入り解説
- レイアウト マネージャを使用する場合
- Nexaweb レイアウト マネージャの使用方法
Nexaweb レイアウトマネージャとは
- BorderLayout
- BoxLayout
- CardLayout
- FlowLayout
- FreeLayout
- GridLayout
レイアウトマネージャの図解入り解説
BorderLayout
<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>
5 つの領域すべてにコンポーネントを配置する必要はありません。実際、2 つか 3 つの領域を使用するだけで目的のレイアウト結果が得られる場合もよくあります。
BoxLayout は、orientation 属性で指定する方向に従って、コンポーネントを 1 つの行または列に配置します。コンポーネントのサイズがコンテナのサイズより大きい場合、コンポーネントは次の行または列に折り返されません。これに対 し、flowLayout では、使用可能なスペースにコンポーネントが折り返されます。BoxLayout のデフォルト設定ではコンポーネントのサイズが優先されるため、コンテナのサイズが変化しても、コンポーネントのサイズは変更されません。次の XML コードの例は、上のウィンドウを表しています。
<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>
<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 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">
<cardLayout show="card2"/>
<label height="20" text="Card 1" width="100" alignHorizontal="center"
alignVertical="center" fontBold="true" fontSize="100" name="card1"/>
<label height="20" text="Card 2" width="100" alignHorizontal="center"
alignVertical="center" fontBold="true" fontSize="100" name="card2"/>
</panel>
</window>
</nxml>
FlowLayout
<window title="window" width="350" height="200">
<flowLayout/>
<button text="button 1"/>
<textField />
<comboBox />
<radioButton text="radio button" />
</window>
FreeLayout
FreeLayout は、各コンポーネントに指定した絶対的なサイズと位置に応じて、コンポーネントを配置します。コンポーネントのサイズや位置を決める場合は、画面のサイズ がコンピュータによって異なることを考慮する必要があります。他のレイアウトマネージャで必要なレイアウトが作成できない場合や、マウスイベントから x/y 座標を使用してコンポーネントをコンテナに追加する場合にFreeLayout を使用します。次の XML コードの例は、上のウィンドウを表しています。
<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 は、コンポーネントを親コンテナに追加する順序に基づいて、同じサイズのグリッド内に、行ごとに 1 つずつ配置します。各コンポーネントのサイズは同じになり、グリッド全体は親コンテナに完全に適合します。グリッドの列数は、columns 属性を使用して指定します。グリッド内の子コンポーネントのサイズや位置を決める場合は、GridLayout 属性に加えて、子コンポーネントの属性を使用できます。次の XML コードの例は、上のウィンドウを表しています。
<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)
(未完成)

