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
Regular Contributor
ricken
Posts: 83
Registered: ‎12-09-2010
My Device: Not Specified
Accepted Solution

Align Field in HorizontalFieldManager

Hello,

I have some issues to right align my custombutton into an HorizontalFieldManager.

I have a simple code like that :

 

public class HeaderManager extends HorizontalFieldManager
{

    public HeaderManager()
    {
        super(Manager.NO_HORIZONTAL_SCROLL| Manager.NO_VERTICAL_SCROLL|  Manager.USE_ALL_WIDTH | Manager.FIELD_RIGHT);
        
    
        this.setBackground(BackgroundFactory.createSolidBackground(Color.RED));
        
        ButtonImage mButtonRefresh =  new ButtonImage("refresh",DrawStyle.RIGHT);
        mButtonRefresh.setMargin(6, 10,0 ,0);
        this.add(mButtonRefresh);
        
    }
    
}

It's a pretty simple code but it doesn't works!

 

My manager take all width but my field stuck on left.

My custom button (ButtonImage) simply extends Field.

 

Is there a way to make it works or we have to do some absolute positionning with layoutChild??

 

Thanks for your help

 

 

 

Developer
ibarrera
Posts: 588
Registered: ‎05-29-2009
My Device: 9100

Re: Align Field in HorizontalFieldManager

I have done the same but in a VerticalFieldManager and using  Field.FIELD_RIGHT as button style and it worked out for me.

Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: Align Field in HorizontalFieldManager

Its a bug in blackberry jde, try following:

1. if you want to add only single field in this manager, then create Vertical Field Manager instead of Horizontal Field Manager.

 

2. If you have two or fields and all of these should be right aligned, then create a VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.FIELD_RIGHT), create a horizontal field manager add all fields to this horizontal manager, and add horizontal manager to vertical manager

 

3. if you have more than one field and these should be aligned differently, then please create a horizontal field manager add fields to this manager you want to align left. create a verticalfieldmanager using full width and field_right. create fields in this manager with style Field.RIGHT or Field.HCENTER according to your needs.

Regular Contributor
ricken
Posts: 83
Registered: ‎12-09-2010
My Device: Not Specified

Re: Align Field in HorizontalFieldManager

Hello,

Thanks, I've used the 2nd solution.

But why the right alignment doesn't works on the HorizontalFieldManager?

Developer
jitendrasharma
Posts: 208
Registered: ‎08-04-2009
My Device: Not Specified

Re: Align Field in HorizontalFieldManager

its a bug, I think.

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

Re: Align Field in HorizontalFieldManager

No, it's not a bug: HorizontalFieldManager orders fields horizontally - how on Earth is it supposed to honor horizontal alignment flags? Same with VerticalFieldManager - it ignores FIELD_TOP, FIELD_BOTTOM and FIELD_VCENTER in much the same way HorizontalFieldManager ignores FIELD_LEFT, FIELD_RIGHT and FIELD_HCENTER.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
New Contributor
TessyJose
Posts: 8
Registered: ‎11-17-2011
My Device: developer

Re: Align Field in HorizontalFieldManager

us this, woked for me :smileyhappy:

 

HorizontalFieldManager horizontalFieldManager =new HorizontalFieldManager(HorizontalFieldManager.FIELD_VCENTER|HorizontalFieldManager.FIELD_HCENTER);

.

.

.

horizontalFieldManager.add(customButton);

add(horizontalFieldManager);

 

Developer
5020379021
Posts: 50
Registered: ‎02-18-2009
My Device: Not Specified

Re: Align Field in HorizontalFieldManager

Hi,

 

I tried your solution writing below codes. I can see the cancel button aligns left and the done button aligns right. But

I cannot find the settings label. Do you guys have any idea on this, please? Thanks  in advance.

 

HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);

horizontalFieldManager.add(new ButtonField("Cancel", ButtonField.FIELD_LEFT));

 

VerticalFieldManager verticalFieldManager = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH); verticalFieldManager.add(new ButtonField("Done", ButtonField.FIELD_RIGHT)); horizontalFieldManager.add(verticalFieldManager);

 

horizontalFieldManager.add(new LabelField("Settings", LabelField.FIELD_HCENTER | LabelField.FIELD_RIGHT ));

 

setTitle(horizontalFieldManager);

Developer
5020379021
Posts: 50
Registered: ‎02-18-2009
My Device: Not Specified

Re: Align Field in HorizontalFieldManager

Hi,

I tried your solution writing below codes. I can see the cancel button aligns left and the done button aligns right. But

I cannot find the settings label. Do you guys have any idea on this, please? Thanks  in advance.

 

HorizontalFieldManager horizontalFieldManager = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
horizontalFieldManager.add(new ButtonField("Cancel", ButtonField.FIELD_LEFT));

VerticalFieldManager verticalFieldManager = new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH); verticalFieldManager.add(new ButtonField("Done", ButtonField.FIELD_RIGHT)); horizontalFieldManager.add(verticalFieldManager);
 
horizontalFieldManager.add(new LabelField("Settings", LabelField.FIELD_HCENTER | LabelField.FIELD_RIGHT )); 

setTitle(horizontalFieldManager);

 

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

Re: Align Field in HorizontalFieldManager

There is no room for your "Settings" label to display. Since the previously added VFM has USE_ALL_WIDTH, it grabs all the remaining width after the "Cancel" button field and leaves zero (nothing) for the label field.

 

What exactly are you trying to achieve? Do you want "Cancel" on the left, "Settings" in the middle and "Done" on the right? You cannot achieve this using the described technique. If you want a pre-existing solution,your best bet is JustifiedEvenlySpacedHorizontalFieldManager from here:

Advanced buttons, fields, and managers

Make sure you read its code so that you have some idea on how this can be achieved in the future.

 

Good luck!

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