Welcome!

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

Reply
Developer
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!