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
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Aligning labelfield in the centre of a Horizontal Field Manager

remove (Display.getHeight()-itemNumber.getHeight())/2 to 0 and then try..
Please use plain text.
Contributor
pk25
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Aligning labelfield in the centre of a Horizontal Field Manager

Thank you. That did the trick :Yes:

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

Re: Aligning labelfield in the centre of a Horizontal Field Manager

In general you should be careful about how you use sublayout.  As an example of the sort of things that you need to be careful of, let us look at this code:

 

protected void sublayout(int maxWidth,int maxHeight) {
 super.sublayout(maxWidth, maxHeight);
 setPositionChild(this.getField(0), (Display.getWidth()-itemNumber.getWidth())/2,(Display.getHeight()-itemNumber.getHeight())/2);
}

 

Nor maxHeight and maxWidth are exactly what you expect - the maximum available space that this Manager has potentially got control over.  Once sublayout is finished, then the code will have done two things:

 

a) Positined the Fields within ithis area - using setPositionChild

b) Returned an indication of the space it actually requires - this is setExtent.

 

In this case, the processing invokes the super  sublayout, so the standadrd HFM processing will take place.  It iwll set the extent and position.  The processing then assumes that it can position one of the Fields itself, without in fact checking if this position is within the confines of the setExtent that has been issued.  There is an assumption here that the Manager will get the entire Display area, whihc is of course invalid - it may not have the entire area to play with.  For example, this could be a Manager used in side a MainScreen which can have a title or a status or a banner area, already taking up screen space. 

 

The following change will guarantee that the field is positioned in a place that will enable it to be seen:

 

 setPositionChild(this.getField(0), (this.getWidth()-itemNumber.getWidth())/2,(this.getHeight()-itemNumber.getHeight())/2);

 

Now this Manager should not use a reference to an external Field, especially when it does not need to.  So this is better again:

 

Field ourOnlyField =  this.getField(0);

setPositionChild(ourOnlyField, (this.getWidth()-ourOnlyField.getWidth())/2,(this.getHeight()-ourOnlyField.getHeight())/2);

 

And finally I think it would be appropriate in this case for the processing to barf if there is 0 or more than 1 Field. 

Please use plain text.
Contributor
pk25
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Aligning labelfield in the centre of a Horizontal Field Manager

Thank you peter_strange for your reply too.

Please use plain text.
Contributor
pk25
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Aligning labelfield in the centre of a Horizontal Field Manager

@peter_strange yes I have used this HFM inside a mainscreen as sort of a header . I ll be inserting a button inside the HFM to go to the next screen.

 

I have a query: Why didn't LabelField.FIELD_HCENTER work ? Shouldn't it have aligned the labelfield in the centre of the HFM?

Please use plain text.
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Aligning labelfield in the centre of a Horizontal Field Manager

i also tried it LabelField.FIELD_HCENTER not work in horizontal manager so i do this in the above way
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Aligning labelfield in the centre of a Horizontal Field Manager

There is a lot more I could add, but you can probably pick up most of it by reading:

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

 

Good luck. 

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

Re: Aligning labelfield in the centre of a Horizontal Field Manager

[ Edited ]

Sorry just seen your last questions.

 

You have to be careful about using the Style attributes to understand:

 

a) the impact they have on the Field

and

b) The impact that they have on the Manager of the Field.

 

And this all depends on the Field, the Manager and the situation.  So one setting, for example FIELD_HCENTER, can have different or in fact no effect depending on the circumstances.

 

In general, the FIELD_* attributes are indications to the Manager of the Field, how it should be treated.  Specifically FIELD_HCENTER is a request that once the Field has sized itself, the Manager should place the Field in the center of the available Horizontal Space. 

 

If we take LabelField, in general this works because a LabelField will only request the width it needs.  However this does NOT work for an EditField - because they always ask for the full width available, even if they are not using it.

 

However it does NOT work in a normal HorizontalFieldManager.  A HFM is laying things out horizontally and so only wants to take up as little width as it possibly can.  So if you have a LabelField in a HFM, it will still be aligned top the Left, because it is in the center of the space the HFM has used - but the HFM has only used a little of the space.

 

When attempting to get layouts like this working, I find it very useful to use the paintBackground trick that you see in my sample code.  Then I know how big each of the areas actually is. 

 

Hope this helps. 

Please use plain text.
Contributor
pk25
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: Aligning labelfield in the centre of a Horizontal Field Manager

[ Edited ]

 What if we pass the USE_ALL_WIDTH paramter to the HFM, it would use up the screen width  and a lot of space would be provided to place its children fields . So that time should't  HCENTER work for the labelfield instead of aligning it to the leftmost corner ?

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

Re: Aligning labelfield in the centre of a Horizontal Field Manager

There are two assumptions you are making

 

a) HFM knows that when you say 'USE_ALL_WIDTH, you actually mean, use all the width available on the Screen.  This is not a valid assumption - HFM can scroll left and right so that its width is, by default, not limited

b) The Manager that the HFM is placed in, may have already got some restrictions on the width that it is allowed to use, and so in fact USE_ALL_WIDTH may not even have the full screen width to play with. 

 

You must also factor in the capability of the Managers to scroll.  So the setting or not of NO_HORIZONTAL_SCROLL may or may not effect the width that the Managers are allowed, or allow themselves to use. 

 

VFM and HFM work really well in the circumstances with which they were designed - i.e. to sequentially lay out Fields vertically and horizontally.  Typically if I have a requirement that is different to this, I will create a custom Manager because I find that these two have inconsistencies that are confusing.  Rather than study these and figure out how they work, I think it is easier to write your own. 

Please use plain text.