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: 21
Registered: ‎03-08-2009
My Device: Not Specified

Re: Align field right in HFM

subclass the RichTextField, and in the subclass, override the layout method as follows:


protected void layout(int width, int height) { super.layout(width, height); setExtent(width - btn.getWidth(), getFont().getHeight()); }


where btn is the ButtonField that you want to place on the right side.


I haven't tried out this exact case, but I had a case where I wanted a RichTextField followed by a Bitmap, and it worked for that.



Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Align field right in HFM

The code crazyllama (great name!) has given you is very useful. 


However you may have to be a little careful with it for two reasons:


a) I think the size of a BitmapField is fixed (depending on the Bitmap), so I think you can validly call 'getWidth()' at any time.  Not sure that you can do that for a ButtonField, where the size may vary depending on the Font.  In addition, I have trouble with getWidth sometimes returning 0 if the Field has not been laid out.  So in this case, where the layout for the text field will occur before the layout of the ButtonField, you might find this code does not work - getWidth() returns 0. 


b) the Storm throws in a few curve balls of its own since it tries to make the ButtonField bigger so you can hit it with your fingers.  And then you have to careful to make sure you recalculate when the Storm is rotated as the available Width has changed.


Sorry I'm not really familiar enough with this area to suggest the perfect solution and do treat what I say above with a pinch of salt too.  However I tend to try to use getPreferredWidth where crazyllama has used getWidth() and then override getPreferredWidth to always return something useful, like the maximum of super.getPreferredWidth() or a number I have calculated for the Field.  But in truth, I avoid doing this if I possibly can.

Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Align field right in HFM

buttonfields do not return the correct preferred width, a bug i filed a while ago. that's one more reason to use bitmapfields with some added click handling (mine is called FocusBitmapField, you can guess why).
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Posts: 96
Registered: ‎03-06-2009
My Device: Not Specified

Re: Align field right in HFM

Hmm ok thanks for the input!


However, I solved it this way:

1 HFM using_all_width in which I put:

- The richtextfield

- 1 VFM using_all_width in which I put my button which is Field.FIELD_RIGHT



Regular Contributor
Posts: 57
Registered: ‎09-22-2010
My Device: Not Specified

Re: Align field right in HFM

After one year and a half another developer comes and thanks you for saving his day!

I don't understand why this ALIGN_RIGHT style property doesn't work for horizontal managers ... Or why it is not documented in an appropriate way in the API.


Anyway, thanks again!