Read-only text field

Use a read-only text field to display read-only text that can be formatted.

Class RichTextField
Supported since BlackBerry® Java® SDK 4.0
Example This screen shows read-only text fields.

For more information about read-only text fields, see the UI Guidelines.

Code sample: Creating a read-only text field

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.component.Dialog;


public class RichTextFieldDemo extends UiApplication
{
    public static void main(String[] args) 
    {
        RichTextFieldDemo theApp = new RichTextFieldDemo();
        theApp.enterEventDispatcher();
    }
    
    public RichTextFieldDemo()
    {
        pushScreen(new RichTextFieldDemoScreen());
    }
}

class RichTextFieldDemoScreen extends MainScreen
{
    Font myFont1, myFont2, myFont3;
    
    public RichTextFieldDemoScreen()
    {
        
        RichTextField title = new RichTextField("Read-only Text Field Demo");
        setTitle(title);
        
        RichTextField rtf1 = new RichTextField("Right-aligned plain", RichTextField.TEXT_ALIGN_RIGHT);
        RichTextField rtf2 = new RichTextField("Centered extra bold", RichTextField.TEXT_ALIGN_HCENTER);
        RichTextField rtf3 = new RichTextField("Left-aligned italic", RichTextField.TEXT_ALIGN_LEFT);
        
        try
        {
            FontFamily ff1 = FontFamily.forName("Times New Roman");
            myFont1 = ff1.getFont(Font.PLAIN, 18);
            
            FontFamily ff2 = FontFamily.forName("Courier New");
            myFont2 = ff2.getFont(Font.EXTRA_BOLD, 24);
            
            FontFamily ff3 = FontFamily.forName("Verdana");
            myFont3 = ff3.getFont(Font.ITALIC, 24);
            
        }
        catch(final ClassNotFoundException cnfe)
        {
            UiApplication.getUiApplication().invokeLater(new Runnable()
            {
                public void run()
                {
                    Dialog.alert("FontFamily.forName() threw " + cnfe.toString());
                }
            });              
        } 

        rtf1.setFont(myFont1);
        rtf2.setFont(myFont2);
        rtf3.setFont(myFont3);
        
        add(rtf1);
        add(rtf2);
        add(rtf3);
    }
}
Next topic: Editable text field
Previous topic: Label

Was this information helpful? Send us your comments.