Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 108
Registered: ‎08-05-2008
My Device: Not Specified

One line TextField

I want to place a TextField object on the form and that works fine.  However, I'd like for the text field to take up the entire width of the screen and allow just one line of text.  By default, it allows multiple lines of text.


How can I accomplish this?



BlackBerry Development Advisor
Posts: 15,876
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: One line TextField

You could set a limit on the number of characters that a user could input to limit the amount of text that can be entered.  The amount that could be entered on a line would vary though based on the user's font size.  You can calculate the size of a string in pixels for the given font by using the Font.getAdvance(string) method to find the exact size or to estimate the number of characters that can fit on the screen width.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: One line TextField

Another approach that I used in the past is to first place the textField in a horizontalManager and set the extent of the manager to whatever size you have. This  will allow you to control the size of the textfield using screen pixels.