Expanders are often used to present small amounts of information to the user. Since the information may not be relevant to the user all the time, expanders allow the user to "collapse" the panel to make more room for other content, similar to rolling up a window shade. The following example demonstrates the use of the Expander component:
The WTKX source for this example is as follows. It declares three expanders contained in a vertical flow pane, which itself is contained in a scroll pane. The contents of the expanders are defined in several external WTKX files that are included by the main file:
<Window title="Expanders" maximized="true" xmlns:wtkx="http://pivot.apache.org/wtkx" xmlns="org.apache.pivot.wtk"> <content> <Border styles="{padding:6}"> <content> <ScrollPane horizontalScrollBarPolicy="fill"> <view> <BoxPane orientation="vertical" styles="{fill:true, padding:{left:2, right:2}}"> <Expander wtkx:id="stocksExpander" title="Stocks"> <content> <wtkx:include src="stocks.wtkx"/> </content> </Expander> <Expander wtkx:id="weatherExpander" title="Weather" expanded="false"> <content> <wtkx:include src="weather.wtkx"/> </content> </Expander> <Expander wtkx:id="calendarExpander" title="Calendar" expanded="false"> <content> <wtkx:include src="calendar.wtkx"/> </content> </Expander> </BoxPane> </view> </ScrollPane> </content> </Border> </content> </Window>
The Java source for this is extremely simple. It serves only to load and display the content defined in the WTKX source:
package org.apache.pivot.tutorials.navigation; 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.Expander; import org.apache.pivot.wtk.ExpanderListener; import org.apache.pivot.wtk.Window; import org.apache.pivot.wtkx.WTKXSerializer; public class Expanders implements Application { private Window window = null; private Expander stocksExpander = null; private Expander weatherExpander = null; private Expander calendarExpander = null; public void startup(Display display, Map<String, String> properties) throws Exception { WTKXSerializer wtkxSerializer = new WTKXSerializer(); window = (Window)wtkxSerializer.readObject(this, "expanders.wtkx"); stocksExpander = (Expander)wtkxSerializer.get("stocksExpander"); weatherExpander = (Expander)wtkxSerializer.get("weatherExpander"); calendarExpander = (Expander)wtkxSerializer.get("calendarExpander"); ExpanderListener expanderListener = new ExpanderListener.Adapter() { public void expandedChanged(Expander expander) { if (expander.isExpanded()) { expander.scrollAreaToVisible(0, 0, expander.getWidth(), expander.getHeight()); } } }; stocksExpander.getExpanderListeners().add(expanderListener); weatherExpander.getExpanderListeners().add(expanderListener); calendarExpander.getExpanderListeners().add(expanderListener); 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(Expanders.class, args); } }
Next: Rollups