If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
New Developer
MrRough
Posts: 5
Registered: ‎10-26-2009
My Device: Not Specified
Accepted Solution

Help figuring out HorizontalLayoutManager and RichTextField Width Issues

[ Edited ]

I'm attempting to have something like this on the screen (4.7 simulator as a Storm)

 

Spacer|RichTextField|Spacer

Spacer|RichTextField|Spacer

Spacer|RichTextField|Spacer

Spacer|RichTextField|Spacer

 

Here is how I'm trying to do it

 

 

HorizontalFieldManager hfm1 = new HorizontalFieldManager();

VerticalFieldManager vfm2 = new VerticalFieldManager();
for (int i = 1; i <= 4; i++) {
  RichTextField rtf = new RichTextField("Hello World " + i);
  vfm2.add(rtf);
}

hfm1.add(new LabelField("!"));
hfm1.add(vfm2);
hfm1.add(new LabelField("!"));

add(hfm1);

 

 

This displays

 

Spacer|RichTextField

 

and not the desired

 

Spacer|RichTextField|Spacer

 

What appears to be happening is that the RichTextFields are too long and I don't know how to fix this. Does anyone have any suggestions on what I'm doing wrong?

 

I've tried overriding getPreferredWidth() but it's not shortening it at all

 

 

for (int i = 1; i <= 10; i++)
{
  RichTextField rtf = new RichTextField("Hello World " + i)
  {
    public int getPreferredWidth()
    {
      return (40);
    }
  };
  vfm2.add(rtf);
}

 

If it helps, Display.getWidth() returns 360 without the above override when in portrait (Top-side-up).

 

Any help is appreciated.

 

Please use plain text.
Developer
yogeswaran
Posts: 69
Registered: ‎07-30-2009
My Device: Not Specified

Re: Help figuring out HorizontalLayoutManager and RichTextField Width Issues

Try This

VerticalFieldManager vfm = new VerticalFieldManager();

for(int i=0;i<=3;i++)
{
   HorizontalFieldManager hmanger = new HorizontalFieldManager();
   hmanger.add(new LabelField("!"));
   RichTextField rtf = new RichTextField("Hello World " + i);
   hmanger.add(rtf);
   hmanger.add(new LabelField("!"));
   vfm.add(hmanger); 
}
add(vfm );

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help figuring out HorizontalLayoutManager and RichTextField Width Issues

[ Edited ]

 

That won't work either, you need to force the width of the RichTextField in the sublayout.


Try the following:

 

    VerticalFieldManager vfm = new VerticalFieldManager();
    HorizontalFieldManager hmanger = new HorizontalFieldManager();
    hmanger.add(new LabelField("!"));
    RichTextField rtf = new RichTextField("Hello World ") {
        public int getPreferredWidth() {
            return 40;
        }
        protected void layout(int arg0, int height) {
            super.layout(getPreferredWidth(), height);
            setExtent(getPreferredWidth(), height);     
        }
    };
    hmanger.add(rtf);
    hmanger.add(new LabelField("!"));
    vfm.add(hmanger); 
    this.add(vfm);

 

 Also, can I just complement the Original Poster on giving us a simple piece of code that worked without needing anything else and demonstrated the problem.  I wish all posts of code were similarly brief and to the point. 

Please use plain text.
New Developer
MrRough
Posts: 5
Registered: ‎10-26-2009
My Device: Not Specified

Re: Help figuring out HorizontalLayoutManager and RichTextField Width Issues

Thank you both for the answers.

 

Overriding the layout() function appeared to work to fix the width. The one thing that did crop up was that the height of the RichTextField became the entire height of the screen. I replaced height with getPreferredHeight(). This appears to work fine, but in case I'm incorrect here it is.

 

 

RichTextField rtf = new RichTextField("Hello World " + i)
{
  public int getPreferredWidth()
  {
    return (40);
  }
				
  protected void layout(int arg0, int height)
  {
    super.layout(getPreferredWidth(), getPreferredHeight());
    setExtent(getPreferredWidth(), getPreferredHeight());     
  }
};

 

 

Please let me know otherwise, but this seems to work.

 

Thank you again.

Please use plain text.