Stack panes arrange their children in layers, like a stack of transparencies. Unlike card panes, which show only a single component at a time, stack panes always display all of their child components. Components with a higher z-index (position within the stack pane) are painted on top of components with a lower z-index.
The following example shows a stack pane containing an image view and a label. The label is layered on top of the image:
The WTKX source for the example is as follows:
<Window title="Stack Panes" maximized="true" xmlns:wtkx="http://pivot.apache.org/wtkx" xmlns="org.apache.pivot.wtk"> <content> <StackPane> <ImageView image="@background.png" styles="{fill:true, preserveAspectRatio:false}"/> <Label text="StackPane Demo" styles="{font:'Helvetica bold 64', color:'#ffffff', wrapText:true, horizontalAlignment:'center', verticalAlignment:'center'}"/> </StackPane> </content> </Window>
The Java code for this example doesn't really do anything interesting; it just loads the WTKX:
package org.apache.pivot.tutorials.layout; import org.apache.pivot.collections.Map; import org.apache.pivot.wtk.Application; import org.apache.pivot.wtk.DesktopApplicationContext; import org.apache.pivot.wtk.Display; import org.apache.pivot.wtk.Window; import org.apache.pivot.wtkx.WTKXSerializer; public class StackPanes implements Application { private Window window = null; public void startup(Display display, Map<String, String> properties) throws Exception { WTKXSerializer wtkxSerializer = new WTKXSerializer(); window = (Window)wtkxSerializer.readObject(this, "stack_panes.wtkx"); window.open(display); } public boolean shutdown(boolean optional) { if (window != null) { window.close(); } return false; } public void suspend() { } public void resume() { } public static void main(String[] args) { DesktopApplicationContext.main(StackPanes.class, args); } }
Next: Split Panes