blackberry java sdk quick reference guide 1203961 0730090020 001 6.0 us

64
BlackBerry Java SDK UI Component Version: 6.0 Quick Reference Guide

Upload: dianadelgadhernandez

Post on 10-Mar-2015

442 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

BlackBerry Java SDKUI ComponentVersion: 6.0

Quick Reference Guide

Page 2: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Published: 2010-11-23SWD-1203961-1208020646-001

Page 3: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Contents1 Text fields...................................................................................................................................................................................... 3

Label................................................................................................................................................................................................. 3

Read-only text field........................................................................................................................................................................ 4

Editable text field............................................................................................................................................................................ 6

Password field................................................................................................................................................................................. 7

Email address field.......................................................................................................................................................................... 9

Search field...................................................................................................................................................................................... 10

Autocomplete text field.................................................................................................................................................................. 13

AutoText edit field........................................................................................................................................................................... 14

Active AutoText edit field............................................................................................................................................................... 16

2 Choice fields................................................................................................................................................................................. 18

Check box......................................................................................................................................................................................... 18

Text-based drop-down list............................................................................................................................................................. 19

Numeric drop-down list................................................................................................................................................................. 20

Date field.......................................................................................................................................................................................... 21

Date picker....................................................................................................................................................................................... 22

File picker......................................................................................................................................................................................... 24

Spin box............................................................................................................................................................................................ 25

Location picker................................................................................................................................................................................ 27

Tree field.......................................................................................................................................................................................... 30

3 Buttons.......................................................................................................................................................................................... 33

Radio button.................................................................................................................................................................................... 33

Toolbar.............................................................................................................................................................................................. 34

Button............................................................................................................................................................................................... 36

4 Activity fields................................................................................................................................................................................ 38

Gauge field...................................................................................................................................................................................... 38

Activity indicator............................................................................................................................................................................. 39

Progress indicator........................................................................................................................................................................... 40

5 Picture fields................................................................................................................................................................................. 43

Bitmap field...................................................................................................................................................................................... 43

Picture scroll field........................................................................................................................................................................... 44

Page 4: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

6 Lists and tables............................................................................................................................................................................ 47

Simple list......................................................................................................................................................................................... 47

Rich list............................................................................................................................................................................................. 48

Table................................................................................................................................................................................................. 50

7 Other components....................................................................................................................................................................... 54

Browser field.................................................................................................................................................................................... 54

Title bar............................................................................................................................................................................................ 55

Map field.......................................................................................................................................................................................... 56

8 Provide feedback......................................................................................................................................................................... 58

9 Document revision history......................................................................................................................................................... 59

10 Legal notice.................................................................................................................................................................................. 60

Page 5: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Text fields 1

LabelUse a label to identify a UI component for a BlackBerry® device user.

Class LabelField

Supported since BlackBerry® Java® SDK 4.0

Example

For more information about labels, see the UI Guidelines.

Code sample: Creating a labelimport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.LabelField;

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

class LabelFieldDemoScreen extends MainScreen

Quick Reference Guide Text fields

3

Page 6: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public LabelFieldDemoScreen() { LabelField title = new LabelField("Label Field Demo", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); LabelField labelField1 = new LabelField("Right-aligned label field", LabelField.FIELD_RIGHT); LabelField labelField2 = new LabelField("Centered label field", LabelField.FIELD_HCENTER | LabelField.FOCUSABLE); LabelField labelField3 = new LabelField("Left-aligned label field", LabelField.FIELD_LEFT);

add(labelField1); add(labelField2); add(labelField3); }}

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

Class RichTextField

Supported since BlackBerry® Java® SDK 4.0

Example

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

Code sample: Creating a read-only text field

Quick Reference Guide Read-only text field

4

Page 7: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

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

Quick Reference Guide Read-only text field

5

Page 8: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

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

Editable text fieldUse an editable text field to allow BlackBerry® device users to type text in a field. You can apply filters to restrict the charactersthat users can type in the text field.

Class BasicEditField

Supported since BlackBerry® Java® SDK 3.7

Example

For more information about editable text fields, see the UI Guidelines.

Code sample: Creating an editable text field

Quick Reference Guide Editable text field

6

Page 9: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.BasicEditField;

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

class BasicEditFieldDemoScreen extends MainScreen{ public BasicEditFieldDemoScreen() { setTitle("Editable Text Field Demo"); BasicEditField enterName = new BasicEditField("Your name: ", ""); BasicEditField enterPhone = new BasicEditField("Work number: ", "", 50, BasicEditField.FILTER_PHONE); add(enterName); add(enterPhone); }}

Password fieldUse a password field when BlackBerry® device users are required to type a password. You can apply filters to restrict the charactersthat users can type in the field. By default, the password field supports all characters.

Class PasswordEditField

Supported since BlackBerry® Java® SDK 4.2.1

Quick Reference Guide Password field

7

Page 10: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about password fields, see the UI Guidelines.

Code sample: Creating a password fieldimport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.BasicEditField;import net.rim.device.api.ui.component.PasswordEditField;

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

class PasswordEditFieldDemoScreen extends MainScreen{ public PasswordEditFieldDemoScreen() { setTitle("Password Field Demo"); BasicEditField enterUsername = new BasicEditField("Username: ", ""); PasswordEditField enterPIN = new PasswordEditField("PIN: ", "", 4, PasswordEditField.FILTER_NUMERIC); add(enterUsername);

Quick Reference Guide Password field

8

Page 11: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

add(enterPIN); }}

Email address fieldUse an email address field when BlackBerry® device users are required to type an email address. This field permits only charactersthat are valid in an email address.

The first space that a user types is replaced automatically with an at sign (@) and any subsequent spaces are replaced withperiods (.).

Class EmailAddressEditField

Supported since BlackBerry® Java® SDK 4.0

Example

For more information about email address fields, see the UI Guidelines.

Code sample: Creating an email address fieldimport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.EmailAddressEditField;

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

Quick Reference Guide Email address field

9

Page 12: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

pushScreen(new EmailAddressEditFieldDemoScreen()); }}

class EmailAddressEditFieldDemoScreen extends MainScreen{ public EmailAddressEditFieldDemoScreen() { setTitle("Email Address Field Demo"); EmailAddressEditField enterEmail = new EmailAddressEditField("Email address: ", ""); add(enterEmail); }}

Search fieldUse a search field to allow BlackBerry® device users to filter a list of words that match the characters that they type in the field.Users can select one of the presented matches or continue typing to further restrict the available choices.

When you create a search field, you must specify a source list. The source list supplies the strings to compare against, which canbe hard-coded or derived from data sources on a BlackBerry device, such as contacts, memos, and tasks.

Class KeywordFilterField

Supported since BlackBerry® Java® SDK 4.5

Example

For more information about search fields, see the UI Guidelines.

Code sample: Creating a search fieldimport net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.collection.ReadableList;import net.rim.device.api.util.Comparator;

Quick Reference Guide Search field

10

Page 13: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import java.util.*;import net.rim.device.api.collection.util.*; import net.rim.device.api.util.StringUtilities;import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;

public class SearchFieldDemo extends UiApplication{ KeywordFilterField _keywordFilterField; CountryList _countryList;

public static void main(String args[]) { SearchFieldDemo theApp = new SearchFieldDemo(); theApp.enterEventDispatcher(); } public SearchFieldDemo() { _countryList = new CountryList(); _countryList.addElement(new Country("Zimbabwe")); _countryList.addElement(new Country("Argentina")); _countryList.addElement(new Country("Brazil")); _countryList.addElement(new Country("Canada")); _countryList.addElement(new Country("Chile")); _countryList.addElement(new Country("China")); _countryList.addElement(new Country("Germany")); _keywordFilterField = new KeywordFilterField(); _keywordFilterField.setLabel(""); _keywordFilterField.setSourceList(_countryList, _countryList); SearchFieldDemoScreen screen = new SearchFieldDemoScreen(); screen.setTitle(_keywordFilterField.getKeywordField()); screen.add(_keywordFilterField); screen.addMenuItem(addElementItem); pushScreen(screen); } void addElementToList(Country country) { _countryList.addElement(country); _keywordFilterField.updateList(); } private final MenuItem addElementItem = new MenuItem("Add country", 0, 0) { public void run() { _keywordFilterField.setKeyword("");

Quick Reference Guide Search field

11

Page 14: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

String[] selections = {"Add","Cancel"}; Dialog addDialog = new Dialog("Add Country", selections, null, 0, null); EditField inputField = new EditField("Country: ",""); addDialog.add(inputField); if(addDialog.doModal() == 0) { addElementToList(new Country(inputField.getText())); } } };}

class SearchFieldDemoScreen extends MainScreen{ public SearchFieldDemoScreen(){};}

class CountryList extends SortedReadableList implements KeywordProvider{ public CountryList() { super(new CountryListComparator()); } void addElement(Object element) { doAdd(element); } public String[] getKeywords(Object element) { if(element instanceof Country) { return StringUtilities.stringToWords(element.toString()); } return null; }

final static class CountryListComparator implements Comparator { public int compare(Object o1, Object o2) { if (o1 == null || o2 == null) throw new IllegalArgumentException("Cannot compare null countries"); return o1.toString().compareTo(o2.toString()); } } }

Quick Reference Guide Search field

12

Page 15: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

class Country{ private String _countryName; public Country(String countryName) { _countryName = countryName; } public String toString() { return _countryName; }}

Autocomplete text fieldUse an autocomplete text field to allow BlackBerry® device users to select from a changing list of words that match the charactersthat they type in the field. Users can select one of the presented matches or continue typing to further restrict the available choices.

When you create an autocomplete text field, you must associate it with a BasicFilteredList object. TheBasicFilteredList supplies the strings to compare against, which can be hard-coded or derived from data sources on aBlackBerry device, such as contacts, memos, and tasks.

Classes AutoCompleteField, BasicFilteredList

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about autocomplete text fields, see the UI & Navigation Development Guide.

Code sample: Creating an autocomplete text field

Quick Reference Guide Autocomplete text field

13

Page 16: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.AutoCompleteField;import net.rim.device.api.collection.util.*;

public class AutoCompleteFieldApp extends UiApplication { public static void main(String[] args) { AutoCompleteFieldApp app = new AutoCompleteFieldApp(); app.enterEventDispatcher(); } AutoCompleteFieldApp() { pushScreen(new HomeScreen()); }}

class HomeScreen extends MainScreen{ public HomeScreen() { setTitle("Autocomplete Text Field Demo"); BasicFilteredList filterList = new BasicFilteredList(); String[] days = {"Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday","Sunday"}; filterList.addDataSet(1,days,"days",BasicFilteredList .COMPARISON_IGNORE_CASE); AutoCompleteField autoCompleteField = new AutoCompleteField(filterList); add(autoCompleteField); }}

AutoText edit fieldUse an AutoText edit field to automatically correct text that a BlackBerry® device user types in the field. The text is correctedbased on the AutoText definition list, which lists common typographic errors and corrections. The text is corrected when the userpresses the Space key.

Class AutoTextEditField

Supported since BlackBerry® Java® SDK 4.0

Quick Reference Guide AutoText edit field

14

Page 17: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about AutoText edit fields, see the UI Guidelines.

Code sample: Creating an AutoText edit fieldimport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.AutoTextEditField;

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

class AutoTextEditFieldDemoScreen extends MainScreen{ public AutoTextEditFieldDemoScreen() { setTitle("AutoText Edit Field Demo"); AutoTextEditField myField = new AutoTextEditField("Description: ", ""); add(myField); }}

Quick Reference Guide AutoText edit field

15

Page 18: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Active AutoText edit fieldUse an active AutoText edit field to check for patterns in text that a BlackBerry® device user types in the field. When a patternis found, the text becomes active and the user can click on the active text to access special menu items. For example, emailaddresses and phone numbers are two of the patterns that are recognized by default.

In addition, when the user presses the Space key, text is corrected based on the AutoText definition list, which lists commontypographic errors and corrections.

Classes ActiveAutoTextEditField

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about active autocomplete text fields, see the UI Guidelines.

Code sample: Creating an active AutoText edit fieldimport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.ActiveAutoTextEditField;

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

class ActiveAutoTextEditFieldDemoScreen extends MainScreen

Quick Reference Guide Active AutoText edit field

16

Page 19: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public ActiveAutoTextEditFieldDemoScreen() { setTitle("Active AutoText Edit Field Demo");

ActiveAutoTextEditField myField = new ActiveAutoTextEditField("Send a message to Mike: \n \n", ""); add(myField); }}

Quick Reference Guide Active AutoText edit field

17

Page 20: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Choice fields 2

Check boxUse check boxes for options that BlackBerry® device users can select or clear. Users can select any number of check boxes in agroup.

Class CheckboxField

Supported since BlackBerry® Java® SDK 3.7

Example

For more information about check boxes, see the UI Guidelines.

Code sample: Creating a check boximport net.rim.device.api.ui.Field;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.component.LabelField;import net.rim.device.api.ui.component.CheckboxField;

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

Quick Reference Guide Choice fields

18

Page 21: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

}

class CheckboxFieldDemoScreen extends MainScreen{ public CheckboxFieldDemoScreen() { LabelField title = new LabelField("Check Box Demo", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH); setTitle(title); CheckboxField checkBox1 = new CheckboxField("Ignore Case", true); CheckboxField checkBox2 = new CheckboxField("Ignore Acronyms", false); add(checkBox1); add(checkBox2); }}

Text-based drop-down listUse a text-based drop-down list for text-based options that BlackBerry® device users can select from a list. Users can select onlyone option at a time.

Class ObjectChoiceField

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about text-based drop-down lists, see the UI Guidelines.

Code sample: Creating a text-based drop-down listimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

Quick Reference Guide Text-based drop-down list

19

Page 22: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

public class TextDropdownListDemo extends UiApplication { public static void main(String[] args) { TextDropdownListDemo theApp = new TextDropdownListDemo(); theApp.enterEventDispatcher(); } public TextDropdownListDemo() { pushScreen(new TextDropdownListDemoScreen()); } }class TextDropdownListDemoScreen extends MainScreen { public TextDropdownListDemoScreen() { setTitle("Drop-down List Demo"); String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Satu rday","Sunday"}; int iSetTo = 2; add(new ObjectChoiceField("Day of the week",choices,iSetTo)); }}

Numeric drop-down listUse a numeric drop-down list for numeric options that BlackBerry® device users can select from a list. Users can select only oneoption at a time.

Class NumericChoiceField

Supported since BlackBerry® Java® SDK 3.6

Example

Quick Reference Guide Numeric drop-down list

20

Page 23: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

For more information about numeric drop-down lists, see the UI Guidelines.

Code sample: Creating a numeric drop-down listimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

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

public NumericDropdownListDemo() { pushScreen(new NumericDropdownListDemoScreen()); } }class NumericDropdownListDemoScreen extends MainScreen { public NumericDropdownListDemoScreen() { setTitle("Drop-down List Demo"); int iStartAt = 1; int iEndAt = 31; int iIncrement = 1; int iSetTo = 10; add(new NumericChoiceField("Day of the month",iStartAt,iEndAt,iIncrement,iSetTo-1)); }}

Date fieldUse a date field to display the date and time.

Class DateField

Supported since BlackBerry® Java® SDK 3.6

Quick Reference Guide Date field

21

Page 24: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about date fields, see the UI Guidelines.

Code sample: Creating a date fieldimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

public class DateFieldDemo extends UiApplication { public static void main(String[] args) { DateFieldDemo theApp = new DateFieldDemo(); theApp.enterEventDispatcher(); } public DateFieldDemo() { pushScreen(new DateFieldDemoScreen()); } }class DateFieldDemoScreen extends MainScreen { public DateFieldDemoScreen() { setTitle("Date Field Demo"); add(new DateField("Date and Time: ", System.currentTimeMillis(), DateField.DATE_TIME)); }}

Date pickerUse a date picker to permit BlackBerry® device users to select a date and time.

Quick Reference Guide Date picker

22

Page 25: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Class DateTimePicker

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about date and time pickers, see the UI Guidelines.

Code sample: Creating a date pickerimport net.rim.device.api.ui.*;import net.rim.device.api.ui.picker.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.database.*;import net.rim.device.api.io.*;import java.util.*;

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

class DatePickerDemoScreen extends MainScreen{ public DatePickerDemoScreen() { setTitle("Date picker demo"); add(new RichTextField("Trying Date Picker"));

Quick Reference Guide Date picker

23

Page 26: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { DateTimePicker datePicker = DateTimePicker.createInstance(); datePicker.doModal(); } }); }}

File pickerUse a file picker to permit BlackBerry® device users to select a file from the BlackBerry device.

Class FilePicker

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about file pickers, see the UI Guidelines.

Code sample: Creating a file pickerimport net.rim.device.api.ui.*;import net.rim.device.api.ui.picker.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.io.*;

public class FilePickerDemo extends UiApplication{ public static void main(String[] args) {

Quick Reference Guide File picker

24

Page 27: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

FilePickerDemo theApp = new FilePickerDemo(); theApp.enterEventDispatcher(); } public FilePickerDemo() { pushScreen(new FilePickerDemoScreen()); }}

class FilePickerDemoScreen extends MainScreen{ public FilePickerDemoScreen() { setTitle("File Picker Demo"); add(new LabelField("Trying file picker")); UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { FilePicker fp = FilePicker.getInstance(); FilePickListener fileListener = new FilePickListener(); fp.setListener(fileListener); fp.show(); } }); }}

class FilePickListener implements FilePicker.Listener { public void selectionDone(String str) { Dialog.alert("You selected " + str); }}

Spin boxUse a spin box for items that BlackBerry® device users can select from an ordered list.

Class TextSpinBoxField

Supported since BlackBerry® Java® SDK 5.0

Quick Reference Guide Spin box

25

Page 28: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about spin boxes, see the UI Guidelines.

Code sample: Creating a spin boximport net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.container.MainScreen;import net.rim.device.api.ui.container.SpinBoxFieldManager;import net.rim.device.api.ui.component.Dialog;import net.rim.device.api.ui.component.TextSpinBoxField;

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

class SpinBoxDemoScreen extends MainScreen{ TextSpinBoxField spinBoxDays; TextSpinBoxField spinBoxMonths; SpinBoxFieldManager spinBoxMgr; public SpinBoxDemoScreen() { setTitle("Spin Box Demo"); final String[] DAYS = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; final String[] MONTHS =

Quick Reference Guide Spin box

26

Page 29: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{"January","February","March","April","May","June","July","August","September", "October","November","December"}; spinBoxMgr = new SpinBoxFieldManager(); spinBoxMgr.setVisibleRows(3);

spinBoxDays = new TextSpinBoxField(DAYS); spinBoxMonths = new TextSpinBoxField(MONTHS); spinBoxMgr.add(spinBoxDays); spinBoxMgr.add(spinBoxMonths); add(spinBoxMgr); } public void close() { Dialog.alert("You selected " + (String)spinBoxDays.get(spinBoxDays.getSelectedIndex()) + " and " + (String)spinBoxMonths.get(spinBoxMonths.getSelectedIndex())); super.close(); }}

Location pickerUse a location picker to permit BlackBerry® device users to select a location from a list of options that you define.

Class LocationPicker

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about location pickers, see the UI Guidelines.

Code sample: Creating a location picker

Quick Reference Guide Location picker

27

Page 30: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import net.rim.blackberry.api.invoke.*;import net.rim.device.api.gps.*;import net.rim.device.api.lbs.picker.*;import net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.component.*;import javax.microedition.location.*;import java.util.Enumeration;

public class LocationPickerApp extends UiApplication{ public static void main(String[] args) { LocationPickerApp app = new LocationPickerApp(); app.enterEventDispatcher(); }

public LocationPickerApp() { pushScreen(new LocationPickerAppScreen()); } static class LocationPickerAppScreen extends MainScreen implements LocationPicker.Listener, FieldChangeListener { private LocationPicker _locationPicker; private ButtonField _buttonField; private LabelField _nameLabel; private LabelField _descLabel; private LabelField _coordLabel; private boolean _mapsPresent = false; LocationPickerAppScreen() { setTitle("Location Picker Demo"); _buttonField = new ButtonField("Choose location", ButtonField.NEVER_DIRTY); _buttonField.setChangeListener(this); add(_buttonField); _nameLabel = new LabelField(); _descLabel = new LabelField(); _coordLabel = new LabelField(); add(_nameLabel); add(_descLabel); add(_coordLabel); Landmark[] landmarks = new Landmark[] {new Landmark("New York", "Times Square", new QualifiedCoordinates(40.757682, -73.98571, Float.NaN, Float.NaN, Float.NaN), null), new Landmark("New York","Central Park", new QualifiedCoordinates(40.783333, -73.966667, Float.NaN, Float.NaN, Float.NaN),

Quick Reference Guide Location picker

28

Page 31: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

null)}; int arraySize = 7; LocationPicker.Picker mapsLocationPicker = null; try { mapsLocationPicker = MapsLocationPicker.getInstance(); _mapsPresent = true; } catch(IllegalStateException ise) { arraySize--; } boolean gpsSupported = GPSInfo.getGPSDataSource() != null; if(!gpsSupported) { arraySize--; } LocationPicker.Picker[] locationPickersArray = new LocationPicker.Picker[arraySize]; locationPickersArray[--arraySize] = EnterLocationPicker.getInstance(false); locationPickersArray[--arraySize] = SuggestedLocationPicker.getInstance("App specific...", landmarks ); locationPickersArray[--arraySize] = RecentLocationPicker.getInstance(); locationPickersArray[--arraySize] = ContactsLocationPicker.getInstance(false); locationPickersArray[--arraySize] = GeotaggedPhotoPicker.getInstance(); if(_mapsPresent) { locationPickersArray[--arraySize] = mapsLocationPicker; } if(gpsSupported) { locationPickersArray[--arraySize] = GPSLocationPicker.getInstance(); } _locationPicker = LocationPicker.getInstance(locationPickersArray); Enumeration globalPickers = _locationPicker.getGlobalLocationPickers(); while (globalPickers.hasMoreElements()) { _locationPicker.addLocationPicker((LocationPicker .Picker)globalPickers.nextElement()); }

Quick Reference Guide Location picker

29

Page 32: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

_locationPicker.setListener(this); } public void locationPicked (LocationPicker.Picker picker, Landmark location) { if(location != null) { _nameLabel.setText("Location name: " + location.getName()); _descLabel.setText("Description: " + location.getDescription()); QualifiedCoordinates coordinates = location.getQualifiedCoordinates(); if(coordinates != null) { StringBuffer buff = new StringBuffer("Coordinates: "); double latitude = coordinates.getLatitude(); double longitude = coordinates.getLongitude(); buff.append("Latitude:"); buff.append(latitude); buff.append(", Longitude: "); buff.append(longitude); _coordLabel.setText(buff.toString()); } if(_mapsPresent) { Landmark[] landmark = {location}; MapsArguments mapsArgs = new MapsArguments(landmark); Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs); } } } public void fieldChanged(Field field, int context) { if(field == _buttonField) { _locationPicker.show(); } } }}

Tree fieldUse a tree field to display components in a hierarchical structure. You can configure tree field nodes to be collapsible.

Class TreeField

Quick Reference Guide Tree field

30

Page 33: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Supported since BlackBerry® Java® SDK 3.7

Example

For more information about tree fields, see the UI Guidelines.

Code sample: Creating a tree fieldimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

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

class TreefieldDemoScreen extends MainScreen{ public TreefieldDemoScreen() { setTitle("Tree Field Demo"); String fieldOne = new String("Parent folder 1"); String fieldTwo = new String("Parent folder 2"); String fieldThree = new String("Sub-folder 1"); String fieldFour = new String("Sub-folder 2"); TreeCallback myCallback = new TreeCallback();

Quick Reference Guide Tree field

31

Page 34: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

TreeField myTree = new TreeField(myCallback, Field.FOCUSABLE); int node1 = myTree.addChildNode(0, fieldOne); int node2 = myTree.addChildNode(0, fieldTwo); int node3 = myTree.addChildNode(node2, fieldThree); int node4 = myTree.addChildNode(node3, fieldFour); myTree.setExpanded(node4, false); add(myTree);

} private class TreeCallback implements TreeFieldCallback { public void drawTreeItem(TreeField _tree, Graphics g, int node, int y, int width, int indent) { String text = (String)_tree.getCookie(node); g.drawText(text, indent, y); } }}

Quick Reference Guide Tree field

32

Page 35: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Buttons 3

Radio buttonUse radio buttons for options that BlackBerry® device users can select from a set of choices. Users can select only one option ineach set of radio buttons.

Class RadioButtonGroup, RadioButtonField

Supported since BlackBerry® Java® SDK 3.6

Example

For more information about radio buttons, see the UI Guidelines.

Code sample: Creating radio buttonsimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

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

Quick Reference Guide Buttons

33

Page 36: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public RadioButtonDemoScreen() { setTitle("Radio Button Demo"); RadioButtonGroup rbg = new RadioButtonGroup(); add(new RadioButtonField("Option 1",rbg,true)); add(new RadioButtonField("Option 2",rbg,false)); }}

ToolbarToolbars provide users with a quick and easy way to access frequent actions for an application or screen. Each toolbar consistsof a set of icons that appears along the bottom of the screen.

Only smartphones in the BlackBerry® Storm™ Series and BlackBerry® Torch™ 9800 smartphones use toolbars.

Package Toolbar

Supported since BlackBerry® Java® SDK 6.0

Example

For more information about toolbars, see the UI Guidelines.

Code sample: Creating a toolbarimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.image.*;import net.rim.device.api.ui.toolbar.*;import net.rim.device.api.util.*;import net.rim.device.api.system.*;import net.rim.device.api.command.*;

Quick Reference Guide Toolbar

34

Page 37: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

public class ToolbarDemo extends UiApplication{ public static void main(String[] args) {

ToolbarDemo theApp = new ToolbarDemo(); theApp.enterEventDispatcher(); } public ToolbarDemo() { // Push a screen onto the UI stack for rendering. pushScreen(new ToolbarDemoScreen()); } private final static class ToolbarDemoScreen extends MainScreen { public ToolbarDemoScreen() { if (ToolbarManager.isToolbarSupported()) { setTitle("Toolbar Demo"); ToolbarManager manager = new ToolbarManager(); setToolbar(manager);

try { Bitmap myBitmap = Bitmap.getBitmapResource("myImg.jpg"); Image myImage = ImageFactory.createImage(myBitmap); /* * To create more buttons, Repeat the following lines * up until manager.add() */ ToolbarButtonField button1 = new ToolbarButtonField(myImage, new StringProvider("butn1")); button1.setCommandContext(new Object() { public String toString() { return "Button1"; } }); button1.setCommand(new Command(new CommandHandler() { public void execute(ReadOnlyCommandMetadata metadata, Object context) { Dialog.alert("Executing command for " + context.toString());

Quick Reference Guide Toolbar

35

Page 38: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

} })); manager.add(new ToolbarSpacer(0)); manager.add(button1); } catch (Exception e) { System.out.println(e.getMessage()); } } else { Dialog.alert("The Toolbar is not supported on this device."); } } }}

ButtonUse a button to allow BlackBerry® device users to perform an action when they click the button.

Class ButtonField

Supported since BlackBerry® Java® SDK 4.0

Example

For more information about buttons, see the UI Guidelines.

For information about advanced buttons , read the knowledge base article at about how to implement advanced buttons, fieldsand managers .

Code sample: Creating a button

Quick Reference Guide Button

36

Page 39: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.container.*;

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

class ButtonFieldDemoScreen extends MainScreen { public ButtonFieldDemoScreen() { setTitle("Button Field Demo"); ButtonField addButton = new ButtonField("Add"); ButtonField delButton = new ButtonField("Delete"); add(addButton); add(delButton); }}

Quick Reference Guide Button

37

Page 40: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Activity fields 4

Gauge fieldUse a gauge field to create a horizontal bar to display a progress indicator or a numeric value.

Class GaugeField

Supported since BlackBerry® Java® SDK 4.2

Example

For more information about gauge fields, see the UI Guidelines.

Code sample: Creating a gauge fieldimport net.rim.device.api.ui.*;import net.rim.device.api.ui.component.GaugeField;import net.rim.device.api.ui.container.*;

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

class GaugeFieldDemoScreen extends MainScreen

Quick Reference Guide Activity fields

38

Page 41: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public GaugeFieldDemoScreen () { setTitle("Gauge Field Demo"); GaugeField percentGauge = new GaugeField("Percent: ", 1, 100, 29, GaugeField.PERCENT); add(percentGauge); }}

Activity indicatorUse an activity indicator to display a visual cue that a task whose duration is unknown is progressing. If you can calculate howlong the task will take, consider using a progress indicator instead.

Class ActivityImageField

Supported since BlackBerry® Java® SDK 6.0

Example

For more information about activity indicators, see the UI Guidelines.

Code sample: Creating an activity indicatorimport net.rim.device.api.system.Bitmap;import net.rim.device.api.ui.*;import net.rim.device.api.ui.component.progressindicator.*;import net.rim.device.api.ui.container.*;

public class ActivityIndicatorDemo extends UiApplication { public static void main(String[] args) { ActivityIndicatorDemo theApp = new ActivityIndicatorDemo();

Quick Reference Guide Activity indicator

39

Page 42: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

theApp.enterEventDispatcher(); } public ActivityIndicatorDemo() { pushScreen(new ActivityIndicatorDemoScreen()); } }

class ActivityIndicatorDemoScreen extends MainScreen{ ActivityIndicatorView view = new ActivityIndicatorView(Field.USE_ALL_WIDTH); ActivityIndicatorModel model = new ActivityIndicatorModel(); ActivityIndicatorController controller = new ActivityIndicatorController();

public ActivityIndicatorDemoScreen () { setTitle("Activity Indicator Demo"); view.setController(controller); view.setModel(model);

controller.setModel(model); controller.setView(view);

model.setController(controller);

Bitmap bitmap = Bitmap.getBitmapResource("spinner.png"); view.createActivityImageField(bitmap, 5, Field.FIELD_HCENTER); add(view); }}

Progress indicatorUse a progress indicator to display a visual cue that a task whose duration can be measured is progressing. If you cannot calculatehow long the task will take, consider using an activity indicator instead.

Class ProgressBarField

Supported since BlackBerry® Java® SDK 6.0

Quick Reference Guide Progress indicator

40

Page 43: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about progress indicators, see the UI Guidelines.

Code sample: Creating a progress indicatorimport net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.component.progressindicator.*;

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

class ProgressIndicatorDemoScreen extends MainScreen{ ProgressIndicatorView view = new ProgressIndicatorView(0); ProgressIndicatorModel model = new ProgressIndicatorModel(0, 100, 0); ProgressIndicatorController controller = new ProgressIndicatorController();

ProgressThread _progressThread;

public ProgressIndicatorDemoScreen() { setTitle("Progress Indicator Demo"); model.setController(controller); view.setModel(model);

Quick Reference Guide Progress indicator

41

Page 44: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

view.setController(controller); controller.setModel(model); controller.setView(view); view.setLabel("Percent completion"); view.createProgressBar(Field.FIELD_HCENTER); add(view); _progressThread = new ProgressThread(); _progressThread.start(); } // A thread that simulates the processing of data class ProgressThread extends Thread { public void run() { for(int i = 0; i <= 100; ++i) { ProgressIndicatorDemoScreen.this.model.setValue(i); try { // Simulate work sleep(250); } catch(InterruptedException ie) { } } } } }

Quick Reference Guide Progress indicator

42

Page 45: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Picture fields 5

Bitmap fieldUse a bitmap field to display bitmap images that a BlackBerry® device user can view.

Class BitmapField

Supported since BlackBerry® Java® SDK 3.7

Example

For more information about bitmap fields, see the Multimedia Development Guide.

Code sample: Creating a bitmap fieldimport net.rim.device.api.system.Bitmap;import net.rim.device.api.ui.UiApplication;import net.rim.device.api.ui.component.BitmapField;import net.rim.device.api.ui.container.MainScreen;

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

Quick Reference Guide Picture fields

43

Page 46: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

class BitmapFieldDemoScreen extends MainScreen{

public BitmapFieldDemoScreen () { setTitle("Bitmap Field Demo"); Bitmap bitmapImage = Bitmap.getBitmapResource("BlackBerry_Data_Stream.jpg"); BitmapField fieldDemo = new BitmapField(bitmapImage); add(fieldDemo); }}

Picture scroll fieldUse a picture scroll field to display a row of images that BlackBerry® device the user can scroll through horizontally.

Class PictureScrollField

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about picture scroll fields, see the UI Guidelines.

Code sample: Creating a picture scroll fieldimport net.rim.device.api.system.*;import net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.decor.*; import net.rim.device.api.ui.extension.component.*;import net.rim.device.api.ui.extension.component.PictureScrollField.*;

public class PictureScrollFieldDemo extends UiApplication{ public static void main(String[] args)

Quick Reference Guide Picture scroll field

44

Page 47: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ PictureScrollFieldDemo theApp = new PictureScrollFieldDemo(); theApp.enterEventDispatcher(); } public PictureScrollFieldDemo() { pushScreen(new PictureScrollFieldDemoScreen()); } }

class PictureScrollFieldDemoScreen extends MainScreen{ public PictureScrollFieldDemoScreen() { setTitle("Picture Scroll Field Demo"); Bitmap[] images = new Bitmap[3]; String[] labels = new String[3]; String[] tooltips = new String[3];

images[0] = Bitmap.getBitmapResource("image1.jpg"); labels[0] = "Label for image 1"; tooltips[0] = "Tooltip for image 1";

images[1] = Bitmap.getBitmapResource("image2.jpg"); labels[1] = "Label for image 2"; tooltips[1] = "Tooltip for image 2";

images[2] = Bitmap.getBitmapResource("image3.jpg"); labels[2] = "Label for image 2"; tooltips[2] = "Tooltip for image 2";

ScrollEntry[] entries = new ScrollEntry[3];

for (int i = 0; i < entries.length; i++) { entries[i] = new ScrollEntry(images[i], labels[i],tooltips[i]); }

PictureScrollField pictureScrollField = new PictureScrollField(150, 100); pictureScrollField.setData(entries, 0); pictureScrollField.setHighlightStyle(HighlightStyle .ILLUMINATE_WITH_SHRINK_LENS); pictureScrollField.setHighlightBorderColor(Color.BLUE); pictureScrollField.setBackground(BackgroundFactory .createSolidTransparentBackground(Color.BLACK, 150));

pictureScrollField.setLabelsVisible(true);

Quick Reference Guide Picture scroll field

45

Page 48: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

add(pictureScrollField); }}

Quick Reference Guide Picture scroll field

46

Page 49: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Lists and tables 6

Simple listUse a simple list to display a list of items as text.

Class SimpleList

Supported since BlackBerry® Java® SDK 6.0

Example

For more information about simple lists, see the UI Guidelines.

Code sample: Creating a simple listimport net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.component.table.*;

public class SimpleListDemo extends UiApplication{ public static void main(String[] args) { SimpleListDemo theApp = new SimpleListDemo(); theApp.enterEventDispatcher(); } public SimpleListDemo() { pushScreen(new SimpleListScreen()); } private static final class SimpleListScreen extends MainScreen

Quick Reference Guide Lists and tables

47

Page 50: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public SimpleListScreen() { super(Manager.NO_VERTICAL_SCROLL); setTitle("Simple List Demo"); add(new LabelField("My list", LabelField.FIELD_HCENTER)); add(new SeparatorField()); Manager mainManager = getMainManager(); SimpleList listField = new SimpleList(mainManager); listField.add("Item 1"); listField.add("Item 2"); listField.add("Item 3"); } }}

Rich listUse a rich list to display a list of items that contain an optional image on the left, a list of labels beside the image and an optionaldescription below the image and labels.

Class RichList

Supported since BlackBerry® Java® SDK 6.0

Example

Quick Reference Guide Rich list

48

Page 51: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

For more information about rich lists, see the UI Guidelines.

Code sample: Creating a rich listimport net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.system.*;import net.rim.device.api.ui.component.table.*;

public class RichListDemo extends UiApplication{

public static void main(String[] args) { RichListDemo theApp = new RichListDemo(); theApp.enterEventDispatcher(); } public RichListDemo() { pushScreen(new RichListScreen()); } private static class RichListScreen extends MainScreen { public RichListScreen() { super(Manager.NO_VERTICAL_SCROLL); setTitle("Rich List Demo"); add(new LabelField("BlackBerry Devices", LabelField.FIELD_HCENTER)); add(new SeparatorField()); Manager mainManager = getMainManager(); RichList list = new RichList(mainManager, true, 2, 1); Bitmap bitmap1 = Bitmap.getBitmapResource("9500.png"); Bitmap bitmap2 = Bitmap.getBitmapResource("9000.png"); list.add(new Object[] {bitmap1, "Device 1", "BlackBerry Smartphone 9500", "Description of Device 1."}); list.add(new Object[] {bitmap2, "Device 2", "BlackBerry Smartphome 9000", "Description of Device 2."}); } }}

Quick Reference Guide Rich list

49

Page 52: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

TableUse a table model to store and display data in a table.

Class TableModel

Supported since BlackBerry® Java® SDK 6.0

Example

For more information about tables, including sorted tables that group items under headers, see the UI Guidelines.

Code sample: Creating a tableimport net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;import net.rim.device.api.ui.component.*;import net.rim.device.api.ui.decor.*;import net.rim.device.api.system.*;import net.rim.device.api.ui.component.table.*;

public class TableModelDemo extends UiApplication{ public static void main(String[] args) { UiApplication app = new TableModelDemo(); app.enterEventDispatcher(); } public TableModelDemo() { pushScreen(new TableModelDemoScreen()); } }

class TableModelDemoScreen extends MainScreen

Quick Reference Guide Table

50

Page 53: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ private RegionStyles _style; private TableModel _tableModel; private TableView _tableView; private TableController _controller;

private static final int NUM_ROWS = 4; private static final int NUM_COLUMNS = 3; private static final int IMAGE_WIDTH = 50; private String modelNum[] = {"8100", "8220", "8300", "8330", "8700g", "8800", "9000", "9500"}; private String modelName[] = {"Pearl", "Pearl Flip", "Curve", "Curve", "8700g", "8800", "Bold", "Storm"}; private String osVersion[] = {"4.3", "4.6", "4.5", "4.6", "4.1", "4.2.1", "4.6", "4.7"}; private String deviceYear[] = {"2006", "2008", "2008", "2008", "2005","2007", "2008", "2008"}; private String deviceInterface[] = {"keyboard/trackball", "keyboard/trackball", "keyboard/trackball", "keyboard/trackball", "keyboard", "keyboard/trackball", "keyboard/trackball", "keyboard/trackball/touch"}; public TableModelDemoScreen() { super(Manager.NO_VERTICAL_SCROLL);

setTitle("Table Model Demo");

_style = new RegionStyles(BorderFactory.createSimpleBorder(new XYEdges(1, 1, 1, 1), Border.STYLE_SOLID), null, null, null, RegionStyles.ALIGN_LEFT, RegionStyles.ALIGN_MIDDLE);

_tableModel = new TableModel();

_tableView = new TableView(_tableModel); _tableView.setDataTemplateFocus(BackgroundFactory .createLinearGradientBackground(Color.WHITE, Color.WHITE, Color.BLUEVIOLET, Color.BLUEVIOLET)); _controller = new TableController(_tableModel, _tableView); _tableView.setController(_controller);

setStyle();

add(new LabelField("BlackBerry Devices", LabelField.FIELD_HCENTER)); add(new SeparatorField()); add(_tableView);

for(int i = 0; i < modelName.length; i++) { String imageFileName = modelNum[i] + ".png";

Quick Reference Guide Table

51

Page 54: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Bitmap bitmap = Bitmap.getBitmapResource(imageFileName);

StringBuffer displayName = new StringBuffer(modelNum[i]);

if(!modelName[i].equals(modelNum[i])) { displayName.append(" ("); displayName.append(modelName[i]); displayName.append(")"); }

_tableModel.addRow(new Object[] {bitmap, displayName.toString(), osVersion[i], deviceYear[i], deviceInterface[i]}); }

}

public void setStyle() { DataTemplate dataTemplate = new DataTemplate(_tableView, NUM_ROWS, NUM_COLUMNS) { public Field[] getDataFields(int modelRowIndex) { Object[] data = (Object[]) _tableModel.getRow(modelRowIndex); Field[] fields = new Field[data.length]; for(int i = 0; i < data.length; i++) { if(data[i] instanceof Bitmap) { fields[i] = new BitmapField((Bitmap) data[i]); } else if(data[i] instanceof String) { fields[i] = new LabelField(data[i], Field.FOCUSABLE); } else { fields[i] = (Field) data[i]; } }

return fields; } };

dataTemplate.createRegion(new XYRect(0, 1, 1, 3), _style);

dataTemplate.createRegion(new XYRect(0, 0, 2, 1), _style); dataTemplate.setRowProperties(0, new TemplateRowProperties(Font.getDefault().getHeight() + (_style.getBorder() == null ? 0 : _style.getBorder().getTop() +

Quick Reference Guide Table

52

Page 55: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

_style.getBorder().getBottom()) + (_style.getMargin() == null ? 0 : _style.getMargin().top + _style.getMargin().bottom)));

for(int i = 1; i < NUM_ROWS; i++) { dataTemplate.createRegion(new XYRect(1, i, 1, 1), _style); dataTemplate.setRowProperties(i, new TemplateRowProperties(Font.getDefault().getHeight() + (_style.getBorder() == null ? 0 : _style.getBorder().getTop() + _style.getBorder().getBottom()) + (_style.getMargin() == null ? 0 : _style.getMargin().top + _style.getMargin().bottom))); }

int width = IMAGE_WIDTH + (_style.getBorder() == null ? 0 : _style.getBorder().getTop() + _style.getBorder().getBottom()) + (_style.getMargin() == null ? 0 : _style.getMargin().top + _style.getMargin().bottom); dataTemplate.setColumnProperties(0, new TemplateColumnProperties(width));

dataTemplate.setColumnProperties(1, new TemplateColumnProperties(Display.getWidth() - width));

_tableView.setDataTemplate(dataTemplate); dataTemplate.useFixedHeight(true); }}

Quick Reference Guide Table

53

Page 56: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Other components 7

Browser fieldUse a browser field to display web content in a BlackBerry® device application.

Class BrowserField

Supported since BlackBerry® Java® SDK 5.0

Example

For more information about browser fields, see the UI & Navigation Development Guide.

Code sample: Creating a browser fieldimport net.rim.device.api.browser.field2.*;import net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;

public class BrowserFieldDemo extends UiApplication{ public static void main(String[] args) { BrowserFieldDemo app = new BrowserFieldDemo(); app.enterEventDispatcher(); }

public BrowserFieldDemo() { pushScreen(new BrowserFieldDemoScreen()); }}

class BrowserFieldDemoScreen extends MainScreen

Quick Reference Guide Other components

54

Page 57: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

{ public BrowserFieldDemoScreen() { BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig(); myBrowserFieldConfig.setProperty(BrowserFieldConfig .NAVIGATION_MODE,BrowserFieldConfig.NAVIGATION_MODE_POINTER); BrowserField browserField = new BrowserField(myBrowserFieldConfig); add(browserField); browserField.requestContent("http://www.blackberry.com"); }}

Title barUse a title bar to provide BlackBerry® device users with information at the top of your application. Most title bars contain onlya title, but title bars can display the following items:

• application icon, descriptive title, and time• application notifications, such as a new message indicator• wireless connection indicators, including the wireless coverage level, network coverage, GPS indicator, Bluetooth® indicator,

and Wi-Fi® connection indicator• battery power indicator• active call indicator

Class StandardTitleBar

Supported since BlackBerry® Java® SDK 6.0

Example

For more information about title bars, see the UI Guidelines.

Code sample: Creating a title bar

Quick Reference Guide Title bar

55

Page 58: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*;

public class TitleBarDemo extends UiApplication { public static void main(String[] args) { TitleBarDemo theApp = new TitleBarDemo(); theApp.enterEventDispatcher(); } public TitleBarDemo() { pushScreen(new TitleBarDemoScreen()); } }class TitleBarDemoScreen extends MainScreen{ public TitleBarDemoScreen() { StandardTitleBar myTitleBar = new StandardTitleBar() .addIcon("my_logo.png") .addTitle("Title Bar Demo") .addClock() .addNotifications() .addSignalIndicator(); myTitleBar.setPropertyValue(StandardTitleBar.PROPERTY_BATTERY_VISIBILITY, StandardTitleBar.BATTERY_VISIBLE_LOW_OR_CHARGING); setTitleBar(myTitleBar); }}

Map fieldUse a map field to display a map in a BlackBerry® device application.

Class MapField

Supported since BlackBerry® Java® SDK 6.0

Quick Reference Guide Map field

56

Page 59: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Example

For more information about map fields and location-based services, see the Location-Based Services Development Guide.

Code sample: Creating a map fieldimport net.rim.device.api.lbs.maps.model.*;import net.rim.device.api.lbs.maps.ui.*;import net.rim.device.api.ui.*;import net.rim.device.api.ui.container.*;

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

class MapScreen extends FullScreen{ public MapScreen() { super( FullScreen.DEFAULT_CLOSE | FullScreen.DEFAULT_MENU ); MapField map = new MapField(); MapAction action = map.getAction(); action.setCentreAndZoom(new MapPoint(43.46518, -80.52237), 3); add(map); }}

Quick Reference Guide Map field

57

Page 60: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Provide feedback 8

To provide feedback on this deliverable, visit www.blackberry.com/docsfeedback.

Quick Reference Guide Provide feedback

58

Page 61: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Document revision history 9

Date Description

29 October 2010 Added the following topics:

• AutoText edit field

• Active AutoText edit field

• Gauge field

• Bitmap field

• Button

• Table

4 October 2010 Added the following topics:

• Map field

24 August 2010 Added the following topic:

• Toolbar

3 August 2010 Initial version.

Quick Reference Guide Document revision history

59

Page 62: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Legal notice 10

©2010 Research In Motion Limited. All rights reserved. BlackBerry®, RIM®, Research In Motion®, and related trademarks, names,and logos are the property of Research In Motion Limited and are registered and/or used in the U.S. and countries around theworld.

Java is a trademark of Oracle America, Inc. Bluetooth is a trademark of Bluetooth SIG. Wi-Fi is a trademark of the Wi-Fi Alliance.All other trademarks are the property of their respective owners.

This documentation including all documentation incorporated by reference herein such as documentation provided or madeavailable at www.blackberry.com/go/docs is provided or made accessible "AS IS" and "AS AVAILABLE" and without condition,endorsement, guarantee, representation, or warranty of any kind by Research In Motion Limited and its affiliated companies("RIM") and RIM assumes no responsibility for any typographical, technical, or other inaccuracies, errors, or omissions in thisdocumentation. In order to protect RIM proprietary and confidential information and/or trade secrets, this documentation maydescribe some aspects of RIM technology in generalized terms. RIM reserves the right to periodically change information thatis contained in this documentation; however, RIM makes no commitment to provide any such changes, updates, enhancements,or other additions to this documentation to you in a timely manner or at all.

This documentation might contain references to third-party sources of information, hardware or software, products or servicesincluding components and content such as content protected by copyright and/or third-party web sites (collectively the "ThirdParty Products and Services"). RIM does not control, and is not responsible for, any Third Party Products and Services including,without limitation the content, accuracy, copyright compliance, compatibility, performance, trustworthiness, legality, decency,links, or any other aspect of Third Party Products and Services. The inclusion of a reference to Third Party Products and Servicesin this documentation does not imply endorsement by RIM of the Third Party Products and Services or the third party in any way.

EXCEPT TO THE EXTENT SPECIFICALLY PROHIBITED BY APPLICABLE LAW IN YOUR JURISDICTION, ALL CONDITIONS,ENDORSEMENTS, GUARANTEES, REPRESENTATIONS, OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDINGWITHOUT LIMITATION, ANY CONDITIONS, ENDORSEMENTS, GUARANTEES, REPRESENTATIONS OR WARRANTIES OFDURABILITY, FITNESS FOR A PARTICULAR PURPOSE OR USE, MERCHANTABILITY, MERCHANTABLE QUALITY, NON-INFRINGEMENT, SATISFACTORY QUALITY, OR TITLE, OR ARISING FROM A STATUTE OR CUSTOM OR A COURSE OF DEALINGOR USAGE OF TRADE, OR RELATED TO THE DOCUMENTATION OR ITS USE, OR PERFORMANCE OR NON-PERFORMANCEOF ANY SOFTWARE, HARDWARE, SERVICE, OR ANY THIRD PARTY PRODUCTS AND SERVICES REFERENCED HEREIN, AREHEREBY EXCLUDED. YOU MAY ALSO HAVE OTHER RIGHTS THAT VARY BY STATE OR PROVINCE. SOME JURISDICTIONSMAY NOT ALLOW THE EXCLUSION OR LIMITATION OF IMPLIED WARRANTIES AND CONDITIONS. TO THE EXTENTPERMITTED BY LAW, ANY IMPLIED WARRANTIES OR CONDITIONS RELATING TO THE DOCUMENTATION TO THE EXTENTTHEY CANNOT BE EXCLUDED AS SET OUT ABOVE, BUT CAN BE LIMITED, ARE HEREBY LIMITED TO NINETY (90) DAYS FROMTHE DATE YOU FIRST ACQUIRED THE DOCUMENTATION OR THE ITEM THAT IS THE SUBJECT OF THE CLAIM.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW IN YOUR JURISDICTION, IN NO EVENT SHALL RIM BE LIABLEFOR ANY TYPE OF DAMAGES RELATED TO THIS DOCUMENTATION OR ITS USE, OR PERFORMANCE OR NON-PERFORMANCE OF ANY SOFTWARE, HARDWARE, SERVICE, OR ANY THIRD PARTY PRODUCTS AND SERVICES REFERENCEDHEREIN INCLUDING WITHOUT LIMITATION ANY OF THE FOLLOWING DAMAGES: DIRECT, CONSEQUENTIAL, EXEMPLARY,INCIDENTAL, INDIRECT, SPECIAL, PUNITIVE, OR AGGRAVATED DAMAGES, DAMAGES FOR LOSS OF PROFITS OR REVENUES,FAILURE TO REALIZE ANY EXPECTED SAVINGS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, LOSS OF

Quick Reference Guide Legal notice

60

Page 63: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

BUSINESS OPPORTUNITY, OR CORRUPTION OR LOSS OF DATA, FAILURES TO TRANSMIT OR RECEIVE ANY DATA, PROBLEMSASSOCIATED WITH ANY APPLICATIONS USED IN CONJUNCTION WITH RIM PRODUCTS OR SERVICES, DOWNTIME COSTS,LOSS OF THE USE OF RIM PRODUCTS OR SERVICES OR ANY PORTION THEREOF OR OF ANY AIRTIME SERVICES, COST OFSUBSTITUTE GOODS, COSTS OF COVER, FACILITIES OR SERVICES, COST OF CAPITAL, OR OTHER SIMILAR PECUNIARYLOSSES, WHETHER OR NOT SUCH DAMAGES WERE FORESEEN OR UNFORESEEN, AND EVEN IF RIM HAS BEEN ADVISEDOF THE POSSIBILITY OF SUCH DAMAGES.

TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW IN YOUR JURISDICTION, RIM SHALL HAVE NO OTHEROBLIGATION, DUTY, OR LIABILITY WHATSOEVER IN CONTRACT, TORT, OR OTHERWISE TO YOU INCLUDING ANY LIABILITYFOR NEGLIGENCE OR STRICT LIABILITY.

THE LIMITATIONS, EXCLUSIONS, AND DISCLAIMERS HEREIN SHALL APPLY: (A) IRRESPECTIVE OF THE NATURE OF THECAUSE OF ACTION, DEMAND, OR ACTION BY YOU INCLUDING BUT NOT LIMITED TO BREACH OF CONTRACT, NEGLIGENCE,TORT, STRICT LIABILITY OR ANY OTHER LEGAL THEORY AND SHALL SURVIVE A FUNDAMENTAL BREACH OR BREACHESOR THE FAILURE OF THE ESSENTIAL PURPOSE OF THIS AGREEMENT OR OF ANY REMEDY CONTAINED HEREIN; AND (B)TO RIM AND ITS AFFILIATED COMPANIES, THEIR SUCCESSORS, ASSIGNS, AGENTS, SUPPLIERS (INCLUDING AIRTIMESERVICE PROVIDERS), AUTHORIZED RIM DISTRIBUTORS (ALSO INCLUDING AIRTIME SERVICE PROVIDERS) AND THEIRRESPECTIVE DIRECTORS, EMPLOYEES, AND INDEPENDENT CONTRACTORS.

IN ADDITION TO THE LIMITATIONS AND EXCLUSIONS SET OUT ABOVE, IN NO EVENT SHALL ANY DIRECTOR, EMPLOYEE,AGENT, DISTRIBUTOR, SUPPLIER, INDEPENDENT CONTRACTOR OF RIM OR ANY AFFILIATES OF RIM HAVE ANY LIABILITYARISING FROM OR RELATED TO THE DOCUMENTATION.

Prior to subscribing for, installing, or using any Third Party Products and Services, it is your responsibility to ensure that yourairtime service provider has agreed to support all of their features. Some airtime service providers might not offer Internet browsingfunctionality with a subscription to the BlackBerry® Internet Service. Check with your service provider for availability, roamingarrangements, service plans and features. Installation or use of Third Party Products and Services with RIM's products and servicesmay require one or more patent, trademark, copyright, or other licenses in order to avoid infringement or violation of third partyrights. You are solely responsible for determining whether to use Third Party Products and Services and if any third party licensesare required to do so. If required you are responsible for acquiring them. You should not install or use Third Party Products andServices until all necessary licenses have been acquired. Any Third Party Products and Services that are provided with RIM'sproducts and services are provided as a convenience to you and are provided "AS IS" with no express or implied conditions,endorsements, guarantees, representations, or warranties of any kind by RIM and RIM assumes no liability whatsoever, in relationthereto. Your use of Third Party Products and Services shall be governed by and subject to you agreeing to the terms of separatelicenses and other agreements applicable thereto with third parties, except to the extent expressly covered by a license or otheragreement with RIM.

Certain features outlined in this documentation require a minimum version of BlackBerry® Enterprise Server, BlackBerry® DesktopSoftware, and/or BlackBerry® Device Software.

The terms of use of any RIM product or service are set out in a separate license or other agreement with RIM applicable thereto.NOTHING IN THIS DOCUMENTATION IS INTENDED TO SUPERSEDE ANY EXPRESS WRITTEN AGREEMENTS OR WARRANTIESPROVIDED BY RIM FOR PORTIONS OF ANY RIM PRODUCT OR SERVICE OTHER THAN THIS DOCUMENTATION.

Research In Motion Limited295 Phillip Street

Quick Reference Guide Legal notice

61

Page 64: Blackberry Java SDK Quick Reference Guide 1203961 0730090020 001 6.0 US

Waterloo, ON N2L 3W8Canada

Research In Motion UK Limited Centrum House 36 Station Road Egham, Surrey TW20 9LF United Kingdom

Published in Canada

Quick Reference Guide Legal notice

62