Static Components

Besides the manifold GUI components that interact with the user, JControl/Wombat furthermore provides some static components to display texts, images or graphical layout elements.


Label

The class Label represents a GUI component which can display a multi line String or an image resource. Different horizontal alignments (left, centered and right) may be specified. Labels allow to place and align texts and images without major programming effort.
The most important methods of Label are shown in table 7.

MethodDescription
Label(String text, int x, int y)Creates a new Label at position x,y with specified inscription. The label's size depends on the text and the font used for this components. Changing the text or the font may change the size of the label.
Label(Resource image, int x, int y)Creates a new Label at position x,y with specified image. The label's size depends on the size of the image. Changing the image may change the size of the label.
Label(String text, int x, int y, int width, int height, int style) {Creates a new Label as above, but here, width and height may be specified (values >0). In this case, changing the label's text will not change the size of the label. The style parameter can be one of the constant values STYLE_ALIGN_LEFT, STYLE_ALIGN_CENTER or STYLE_ALIGN_RIGHT. This value can optionally be combined by ORing with STYLE_SHOW_BORDER and STYLE_DRAW_INVERSE, or STYLE_DRAW_NORMAL.
Label(Resource image, int x, int y, int width, int height, int style)Creates a new Label as above, but with an image instead of a text.
setText(String text)Replaces the label's content by the specified text.
setImage(Resource image)Replaces the label's content by the specified image.
setStyle(int style)Changes the style of the label. The is used similar to the contructor.
Table 7: Methods of class jcontrol.ui.wombat.Label


Border

Class Border, which has already been used in previous program examples, can be used to draw different types of borders on the display. The borders are transparent and therefore do not cover already existing GUI components. A String can be passed on construction, which will be displayed left aligned in the upper edge of the Border.

MethodsDescription
Border(String label, int x, int y, int width, int height, int style)Creates a Border with specified inscription, position and size. For the style parameter the following constants can be used: STYLE_SIMPLE_BORDER, STYLE_ROUND_BORDER and STYLE_ETCHED_BORDER.
setText(String label)Changes the Borders' label.
Table 8: Methods of class jcontrol.ui.wombat.Border

The program example WombatLabelBorderExample.java demonstrates the usage of Label and Border. It is located in the directory "demos/cobra5329/WombatTutorial/WombatLabelBorderExample" of your JControl/IDE installation (on Windows "C:\Program Files\JControl\demos\cobra5329\WombatTutorial\WombatLabelBorderExample"). Figure 5 shows a screenshot of this program.

Figure 5: The WombatLabelBorderExample

1    /**
2     * <p>This example demonstrates how to use the
3     * components Label and Border within the GUI
4     * framework JControl/Wombat.
5     * This program needs the image resource
6     * 'smile.jcif'.</p>
7     *
8     * <p>(C) DOMOLOGIC Home Automation GmbH 2007/p>
9     */
10    import jcontrol.ui.wombat.Frame;
11    import jcontrol.ui.wombat.Container;
12    import jcontrol.ui.wombat.Border;
13    import jcontrol.ui.wombat.Label;
14    import jcontrol.io.Resource;
15    import java.io.IOException;
16    import jcontrol.graphics.Color;
17    
18    public class WombatLabelBorderExample extends Frame 
19    
20        /**
21         * Constructor WombatLabelBorderExample
22         */
23        public WombatLabelBorderExample() {
24            // create a container for the content of this frame
25            Container content = new Container();
26           
27            // create some borders of different kind
28            Border simpleBorder = new Border("Simple Border", 70, 30, 160, 50,
29                Border.STYLE_SIMPLE_BORDER);
30            content.add(simpleBorder);
31            Border roundBorder = new Border("Round Border", 70, 80, 160, 50,
32                Border.STYLE_ROUND_BORDER);
33            content.add(roundBorder);
34            Border etchedBorder = new Border("Etched Border", 70, 130, 160, 50,
35                Border.STYLE_ETCHED_BORDER);
36            content.add(etchedBorder);
37           
38            // create some labels of different kind
39            try {
40                Label label1 = new Label(new Resource("smile.jcif"), 140, 47, 0, 0,
41                    Label.STYLE_ALIGN_LEFT);               
42                content.add(label1);
43            } catch(IOException ioe) {
44                // must be caught as the Resource-constructor may throw this exception
45            }      
46            Label label2 = new Label("Hello World!", 120, 97, 60, 20,
47                Label.STYLE_ALIGN_CENTER);
48            label2.setForegroundColor(Color.WHITE);
49            label2.setBackgroundColor(Color.RED);
50            content.add(label2);
51            Label label3 = new Label("Hello World!", 120, 147, 60, 20,
52                Label.STYLE_ALIGN_CENTER|Label.STYLE_SHOW_BORDER);
53            label3.setBackgroundColor(Color.WHITE);    
54            content.add(label3);
55           
56            // set the content to this frame
57            setContent(content);
58            // finally, make the frame visible     
59            setVisible(true);
60        }
61    
62        /**
63         * The main method.
64         *
65         * @param args
66         *        The main arguments
67         */
68        public static void main(String[] args) {
69            new WombatLabelBorderExample();
70        }
71    }
Listing 5: WombatLabelBorderExample.java