This section introduces two of the least complex but most common Pivot components: Label and ImageView. Labels are used to present a block of static, optionally wrapped, text, and image views are used to display a static graphic. The applet below shows an ImageView followed by a Label:
Below is the WTKX source used to generate the applet's contents. Note that the ImageView element defines a cursor attribute with a value of "crosshair". Move the mouse pointer over the image to see the effect.
<Window title="Labels" maximized="true" xmlns:wtkx="http://pivot.apache.org/wtkx" xmlns="org.apache.pivot.wtk"> <content> <BoxPane styles="{padding:4, verticalAlignment:'center'}"> <ImageView image="org/apache/pivot/tutorials/clock.png" cursor="crosshair"/> <Label text="What time is it?"/> </BoxPane> </content> </Window>
Also note that the example uses a BoxPane to arrange the components horizontally. BoxPane is discussed in more detail in the Layout Containers section.
Finally, note that, while the graphic used in this example is a static bitmap (represented by the org.apache.pivot.wtk.media.Picture class), ImageView is also capable of presenting vector graphic images, represented by the org.apache.pivot.wtk.media.Drawing class. Drawings are discussed in more detail in the Drawing section.
The application code used in this example is not significantly different from the code used in the "Hello, World!" example. It simply loads the WTKX file and opens the window:
package org.apache.pivot.tutorials.labels; 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 Labels 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, "labels.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(Labels.class, args); } }
Next: Buttons