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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Horizontal scrollable text edit field issue on 6.0 devices

I guess the only way to truly disable this unbounded scrolling is by restricting the width of the EditField within the HorizontalFieldManager, as I suggested in reply #4.


Some general information first:

1. EditField always consumes the full width available - whatever width parameter its layout gets, that whole width is used in its setExtent. So either layoutChild with that EditField as the first parameter should restrict the available width or EditField's layout should be overridden to use only as much width as needed. Personally, I lean on the side of layoutChild, since the Manager is better aware of its environment and the actual width given to it.

2. Built-in Managers treat VERTICAL_SCROLL and HORIZONTAL_SCROLL style bits like this:

  a) they enable scrolling in the indicated direction;

  b) they make 0x3FFFFFFF width/height (for horizontal/vertical scrolling, respectively) available to their "children" (managed fields) during sublayout, passing appropriate values to each layoutChild;

  c) after the managed fields layout themselves, they calculate total width/height taken by the children and use them as parameters in their setVirtualExtent calls. This "virtual extent" tells the BlackBerry framework the limits of this Manager's scrolling.


Since we are going to seriously override the Manager's sublayout, we don't want to use HorizontalFieldManager for it anymore. Instead, we should extend a Manager and implement its sublayout based on our knowledge on how it will be used. We know that _textMgr will have exactly one "child" - the EditField, so we act accordingly.

Here is some sample code - it is untested but should give enough ideas:

Manager _textMgr = new Manager(HORIZONTAL_SCROLL) {
  protected void sublayout(int maxWidth, int maxHeight) {
    EditField ef = (EditField)getField(0);
    // I'm adding space to the text for the cursor
    int textWidth = ef.getFont().getAdvance(ef.getText() + " ");
    int screens = textWidth / maxWidth + 1;
    layoutChild(ef, maxWidth * screens, maxHeight);
    setPositionChild(ef, 0, 0);
    int totalWidth = ef.getWidth();
    int totalHeight = ef.getHeight();
    setVirtualExtent(totalWidth, totalHeight);
    setExtent(Math.min(totalWidth, maxWidth), Math.min(totalHeight, maxHeight));

See where this code fits better - in the original code from the article or in the code from comment #4. 

please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!