Method | Description |
ListBox(String[] items, int x, int y, int width, int height, int style) | Creates a new GUI component ListBox with the given position an size. The parameter items represents the initial content of the ListBox. The style parameter specifies look and behaviour. All possible values are specified by constant fields in the class ListBox STYLE_NONE , STYLE_SHOW_BORDER , STYLE_SHOW_SCROLLBAR , STYLE_ALIGN_TOP and STYLE_ALIGN_CENTER . The values may even be combined by | in cases were it makes sense. |
ListBox(int x, int y, int width, int height, boolean style) | This constructor works like the one above, with the difference that the Listbox is left empty. |
add(String item) | Adds a new entry to the ListBox . |
remove(String item) | Removes an entry from the ListBox . |
Method | Description |
TextViewer(int x, int y, int width, int height, int style) | Creates a new TextViewer with the given coordinates. width and height specify the components' size. The style parameter specifies look and behaviour. All possible values are specified by constant fields in the class TextViewer STYLE_NONE , STYLE_SHOW_BORDER , STYLE_SHOW_SCROLLBAR . |
TextViewer(String text, int x, int y, int width, int height, int style) | This TextViewer constructor additionally equips the component with an initial text . |
set(String text) | Sets the given text into the TextViewer . Any existing text will be discarded. |
add(String item) | Adds the given text to the TextViewer's content. If the TextViewer doesn't contain any text yet, the method is equal to set(String text) . |
1 | /** |
2 | * <p>This example demonstrates how to use the |
3 | * components ListBox and TextViewer within the GUI |
4 | * framework JControl/Wombat.</p> |
5 | * |
6 | * <p>(C) DOMOLOGIC Home Automation GmbH 2007</p> |
7 | */ |
8 | import jcontrol.ui.wombat.Frame; |
9 | import jcontrol.ui.wombat.Container; |
10 | import jcontrol.ui.wombat.event.ActionListener; |
11 | import jcontrol.ui.wombat.TextViewer; |
12 | import jcontrol.io.Resource; |
13 | import java.io.IOException; |
14 | import jcontrol.ui.wombat.ListBox; |
15 | import jcontrol.ui.wombat.event.ActionEvent; |
16 | |
17 | |
18 | public class WombatListTextviewerExample extends Frame implements ActionListener { |
19 | /** |
20 | * Constructor WombatListTextviewerExample |
21 | */ |
22 | public WombatListTextviewerExample() { |
23 | // create a container for the content of this frame |
24 | Container content = new Container(); |
25 | try { |
26 | // set a larger Font to the content, all components in the |
27 | // content will get this font, too |
28 | content.setFont(new Resource("Arial.jcfd")); |
29 | } catch(IOException ioe) {} |
30 | |
31 | // create a TextViewer |
32 | TextViewer textViewer = new TextViewer( |
33 | "The TextViewer can show any text you want.\n" + |
34 | "Line-breaks are performed autmatically.", |
35 | 70, 40, 180, 70, TextViewer.STYLE_SHOW_SCROLLBAR); |
36 | content.add(textViewer); |
37 | |
38 | // create a ListBox |
39 | ListBox listBox = new ListBox(new String[]{ |
40 | "North", "Eath", "South", "West", |
41 | "North-Eath", "South-West", "South-Eath", "North-West"}, |
42 | 70, 110, 180, 70, ListBox.STYLE_SHOW_SCROLLBAR); |
43 | content.add(listBox); |
44 | listBox.setActionListener(this); |
45 | |
46 | // set the content to this frame |
47 | setContent(content); |
48 | // finally, make the frame visible |
49 | setVisible(true); |
50 | } |
51 | |
52 | /** |
53 | * This method is called every time an item in the listbox declared |
54 | * above is selected be the user. |
55 | * |
56 | * @param e the ActionEvent fired by the listbox |
57 | */ |
58 | public void onActionEvent(ActionEvent e) { |
59 | // add some code if you want to |
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 WombatListTextviewerExample(); |
70 | } |
71 | } |