Previous Up Next
Quick start guide Quick start guide Layouts

Basic Widgets

Label

A label is a collection is characters that cannot be modified by the user.

To place a label on your shell, use the following code:

$label =& new Label($shell);
$label->set_text("Label's text");

Text

A text widget contains text that can normally be modified by the user.

To place a text widget on your shell, use the following code:

$text =& new Text($shell);
The text widget has some properties that can be set. If your text is editable, you can set the maximum number of characters that can be typed:
$text->set_text_limit(50);

Button

A button is a widget that is clicked by the user in order to initiate some processing.

To place a button on the shell, use the following code:

$button =& new Button($shell);
To set the text of the button, use the set_text() method:
$button->set_text("Hello");
A basic event handler for the button is a selection event handler. This is called when the button is selected by clicking on it. To create the event handler, we create an adapter class first:
class SelectionAdapter {
  function widget_selected(&$widget) {
    alert("Button was clicked");
  }
}
Add a listener to the button using the following code:
$button->add_selection_listener(new SelectionAdapter());

Select

A select is a widget that contains a collection of items; the user may select an item from the list.

To place a select widget on your shell, use the following code:

$select =& new Select($shell);
To add items to a select, you can use the set_items() method, or the add() method.
$select->add("One");
$select->set_items(array("One", "Two", "Three"));
Use the set_selection() method to select one of the list items. This method takes an integer argument - the index of the item to be selected.

Composite

A composite is a widget that can contain other widgets. Widgets are placed inside a composite in the same manner that widgets are placed on a shell. The position of each widget inside a composite is relative to the composite, so if the composite is moved on the shell, the widgets inside the composite retain their relative positions.

To place a composite on your shell, use the following code:

$composite =& new Composite($shell);
You can place a control onto a composite in the same way you would add a control to a shell:
$label =& new Label($composite);
$label->set_text("Composite label's text");

Group

A group is also a widget that can contain other widgets. A group is surrounded by a border and may, optionally, contain a title. As with composites, the position of each widget inside a group is relative to the group, so if the group is moved on the shell, the widgets inside the group retain their relative positions.

To place a group on your shell, use the following code:

$group =& new Group($shell);
The principal use of a group is to separate other controls into sections. A group is a subclass of composite, and works in very much the same way. It has additional functionality though, such as setting the text:
$group->set_text("Group 1");
You can place a control onto a group in the same way you would add a control to a shell or a composite:
$button =& new Button($group);

Previous Up Next
Quick start guide Quick start guide Layouts

Documentation generated on Wed, 2 Feb 2005 09:33:48 +0100 by phpDocumentor 1.3.0RC3