StringItem

StringItem is an item that can contain static text, hyperlinks and buttons. A StringItem is always non-editable, although both the label and the textual content of a StringItem may be modified by the application. The font of the label text can not be set.

The intended behavior is defined by setting the appearance mode to be one of the following: PLAIN, HYPERLINK, or BUTTON.

If the StringItem contains a long text, the text forms a paragraph that wraps on the screen. Text wrapping in a paragraph is based on word boundaries. A newline character embedded in StringItem text creates a new line. If the appearance mode set is BUTTON only one line of text is possible. In BUTTON mode an embedded newline character truncates the text, and an ellipsis character is shown.

Figure: An example StringItem

Source code for the example:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
 
public class ExampleForm5 extends MIDlet {
    private Display display;
    private Form form;
    private Command exit;
    
    public ExampleForm5() {
        form = new Form("Form example 5");
        // StringItem(label, text);
        StringItem sItem = new StringItem("Text Example", "Hello World!");
        form.append(sItem);
        exit = new Command("Exit", Command.EXIT, 1);
        form.addCommand(exit);
        form.setCommandListener(this);    }
 
    public void startApp() {
        display = Display.getDisplay(this);        
        display.setCurrent(form);
    }    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    public void commandAction(Command command, Displayable displayable) {
        if (command == exit) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

If the StringItem is null, empty or just whitespace, only the label is displayed.

A newline (/n) character embedded in a StringItem creates a new line.

Concatenation

If there are two consecutive StringItems (SI 1 and SI 2), and SI 2 has an empty label, the text of SI 1 continues in SI 2. Depending upon the Unicode character properties of the last character of SI 1 and the first character of SI 2 (hereafter C1 and C2 respectively) a separator may be required between them. If both C1 and C2 are characters used in Chinese, Japanese, Korean or Thai, no separator is required, because these languages do not use word separators. If either C1 or C2 is any other character (e.g. Latin, Cyrillic), indicating a language that uses word separators, a single space character is inserted between C1 and C2.

The exception to the concatenation behavior is when one or more of the StringItems has got an appearance mode BUTTON. In this circumstance concatenation will only occur if the StringItem(s) with appearance mode BUTTON can fit entirely into a single row. If it/they cannot fit completely into one row then a row break is forced before the StringItem and it is displayed on a new row.

Visual presentation

ImageItems with appearance mode PLAIN are always displayed in the Formin black text with no border surrounding them (these ImageItems can never be focused).

If a StringItem with appearance mode BUTTON can fit entirely on a single row then it will be displayed there, if it doesn’t fit entirely on one row then a new line is forced before and after it.

The way the actual visual behavior is selected is presented in the table below.

Table: Appearance mode of ImageItem or StringItem

Appearance mode set

One or more Item Commands

Visual presentation

PLAIN

Yes

Hyperlink

PLAIN

No

Plain text

HYPERLINK

Yes

Hyperlink

HYPERLINK

No

Plain text

BUTTON

Yes

Button

BUTTON

No

Plain text