Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011
Accepted Solution

TextField operation

Hi,

 

I am wanting to write a paragraph of text and display this on the screen within my app. I'm sure I read that the TextField operation creates an editable text box on the screen. What way would you suggest to creating this paragraph? Would I simply use many LabelFields?

 

Thanks

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: TextField operation

You can use a TextField or its descendants (such as EditField) to display the text. If you make it NON_FOCUSABLE, the user will not be able to navigate to it. If you make it FOCUSABLE | READONLY, the user will be able to navigate there, select some text and copy it (to paste somewhere else, maybe), but will not be able to edit the contents.

 

Hope this helps.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011

Re: TextField operation

Thanks for the swift response :smileyhappy: 

 

How would I go about declaring the TextField and adding it to my existing code? Do you have an example to go by? Am I correct in assuming I will need to add it to my VerticalFieldManager backgroundManager.

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: TextField operation

Yes, just add it to your scrolling manager. It might look like this:

 

TextField copyrightField = new TextField(TextField.FOCUSABLE | TextField.READONLY);
copyrightField.setText(myCopyrightText);
mainVFM.add(copyrightField);

Simple but effective. In this particular case, if your text is too long and your manager is scrolling, the user will be able to scroll through the whole text with regular navigationMovements (trackball / trackpad, swipe / move on a touchscreen).

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011

Re: TextField operation

Hi,

 

I tried to add your suggestion but I receive certain errors and am not sure as to why this is.

 

 

TextField copyrightField = new TextField(TextField.FOCUSABLE|TextField.READONLY);
copyrightField.setText("Hello");
backgroundManager.add(copyrightField);

 

FOCUSABLE and READONLY are displaying errors, as are both "setText" and "add"

 

Please use plain text.
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011

Re: TextField operation

Made the TextField a RichTextField and this solved the issue

 

Thanks

Ash

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: TextField operation

There are two TextFields:

 

javax.microedition.ui.TextField

net.rim.device.api.ui.component.TextField

 

Make sure you are importing the second (highlighted) one.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011

Re: TextField operation

Thanks for that. One other thing, do you know of a way to override the getPrefferedWidth() function for the size of the text box? At the minute the text overlaps with other items on my screen so I'd like to make the width smaller.

 

Thanks

 

Please use plain text.
Developer
arkadyz
Posts: 2,146
Registered: 07-08-2009
My Carrier: various

Re: TextField operation

This is a separate issue so you'd better start a new topic. Before you do that, though, search the board for "limit width", "layout override" and similar - you are bound to find something useful.

 

getPreferredWidth() is simply overridden, no tricks here. The problem is - parent managers totally ignore it when laying out the fields. RichTextField at least has USE_TEXT_WIDTH, but it is useless for text that is more than one line.

 

Oh, and if you start the new topic, please describe what do you mean by "overlaps with other items" - Fields do not normally overlap on the screen no matter what their width or "preferred width" is...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Regular Contributor
ash_1987uk
Posts: 98
Registered: 03-10-2011

Re: TextField operation

Hi, 

 

I have just managed to overcome the issue by using setMargin()

 

Thanks for your help :smileyhappy: 

Please use plain text.