Would you like to tell us how we are doing?

You bet No thanks

Sorry about the red box, but we really need you to update your browser. Read this excellent article if you're wondering why we are no longer supporting this browser version. Go to Browse Happy for browser suggestions and how to update.

Text field: read-only

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

Class

RichTextField

Supported since

BlackBerry Java SDK 4.0

More information

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

Example

This screen shows read-only text fields.

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);
    }
}