List and TextArea

The GUI component List shows a list of strings and enables the user to graphically choose one entry. If the list contains more entries than it is possible to show at one time, a ScrollBar on the components' right side can be enabled. Currently selected entries are marked by inverting the correspondent line. The List component fires ActionEvents of type ITEM_SELECTED. Following methods are available to create a List:

MethodDescription
List(int x, int y, boolean scrollbar)Creates a new GUI component List at the given position. The Parameter scrollbar enables or disables a ScrollBar at the right component border. Since this constructor lacks parameters for the components height and width, its preferred size will be assigned.
List(int x, int y, int width, int height, boolean scrollbar)This constructor works like the one above, with the minor differnce that the programmer is able to set the components size by passing values for the parameters width and height.
add(String item)Adds a new entry to the List.
remove(String item)Removes an entry from the List.
Tabelle 5: Methods of class jcontrol.ui.vole.List

The TextArea can display texts with an optional scroll functionality. Its content may be added statically, by using the appropriate constructor, or dynamically, by using the add method. Invoking the method remove will delete the specified line from the text. Table 6 sums up the methods of the TextArea component:

MethodDescription
TextArea(int x, int y, int width, int height, boolean showScrollbar)Creates a new TextArea at the given coordinates. width and height specify the components' size and the Parameter scrollbar enables or disables a ScrollBar at the right component border.
TextArea(String[] text, int x, int y, int width, int height, boolean showScrollbar)This TextArea constructor additionally equips the component with an initial text.
add(String item)Adds a new line to the TextArea, containig a text specified by the parameter item. The passed text line may not be longer than the TextAreas' width or else it will be cut down to fit into the TextArea by deleting the trailing characters.
remove(int row)Removes line row from the TextArea. The following lines will accordingly move up.
Table 6: Methods of class jcontrol.ui.vole.TextArea

The following source code example includes both a List object and a TextArea, that will be filled with entries and drawn to the display. Open the project file VoleListTextareaExample.jcp from the archive VoleListTextareaExample.zip in your JControl/IDE to see the example in action. Figure 4 shows a screenshot of this program.

Figure 4: The VoleListTextareaExample

1    import jcontrol.ui.vole.Frame;
2    import jcontrol.ui.vole.List;
3    import jcontrol.ui.vole.TextArea;
4    
5    /**
6     * <p>This example demonstrates how to use the
7     * components List and TextArea within the GUI
8     * framework JControl/Vole.</p>
9     *
10     * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p>
11     */
12    public class VoleListTextareaExample extends Frame {
13     
14      /**
15       * Create a List and a TextArea.
16       */
17      public VoleListTextareaExample() {
18        // create a list with some entries
19        List l = new List(0, 0, 128, 31, true);
20        l.add("North");
21        l.add("South");
22        l.add("East");
23        l.add("West");
24        l.add("North-East");
25        l.add("North-West");
26        l.add("South-East");
27        l.add("South-West");
28        this.add(l);
29       
30        // create a TextArea
31        TextArea ta = new TextArea(new String[]{"The TextArea",
32                                                 "can be filled",
33                                                 "up with nonsense",
34                                                 "and nobody really",
35                                                 "cares about it."},
36                                   0, 32, 128, 32, true);
37        this.add(ta);
38      }
39    
40      /**
41       * Instantiate the VoleListTextareaExample
42       */
43      public static void main(String[] args) {
44        new VoleListTextareaExample().show();
45      }
46    }
Listing 4: VoleListTextareaExample.java