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
Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent
Accepted Solution

Align 3 Fields one at left,one at center and one at right

i have 3 field 

first is button i want to put at left

second is label i want to put at center

third  is button i want to put at right

 

all 3 field at one single line

 

please anybody help me

 

Contributor
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

It sure is nasty, but this is the only way to do it without having to install an external class:

// Left aligned vfm to hold the button
VerticalFieldManager left = new  VerticalFieldManager(Manager.FIELD_LEFT);
ButtonField leftbutton = new ButtonField("left");
left.add(leftbutton);
        
// Centre aligned vfm to hold the label
VerticalFieldManager centre = new VerticalFieldManager(Manager.FIELD_HCENTER);
LabelField centrelabel = new LabelField("Centre");
centre.add(centrelabel);
        
// Right aligned vfm to hold the button
VerticalFieldManager right = new VerticalFieldManager(Manager.FIELD_RIGHT); 
ButtonField rightbutton = new ButtonField("right");
right.add(rightbutton);       
        
// Create a 3x1 evenly spaced grid to hold the above vfms
GridFieldManager gridFieldManager = new GridFieldManager(1,3, Manager.USE_ALL_WIDTH); 
gridFieldManager.setColumnProperty(0, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(1, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setColumnProperty(2, GridFieldManager.AUTO_SIZE, 0);
gridFieldManager.setRowProperty(0, GridFieldManager.AUTO_SIZE, 0);

// Add the left vfm to the grid
VerticalFieldManager vfmLeft = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmLeft.add(left);
gridFieldManager.add(vfmLeft);  

// Add the centre vfm to the grid
VerticalFieldManager vfmCentre = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmCentre.add(centre);
gridFieldManager.add(vfmCentre);
        
// Add the right vfm to the grid
VerticalFieldManager vfmRight = new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT );
vfmRight.add(right);
gridFieldManager.add(vfmRight);

add(gridFieldManager);   

 

Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

it works but there is space lines after the fields how can i remove this lines
Contributor
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

Space lines? Are you getting the same as me:

 



    

Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

Untitled.png

 

lines after fields why i want only one line

Contributor
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

When I compile that snippet and run it on the Bold 9900 simulator, all three items are on a single line and aligned as you wanted.

What version are you running?

Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

9900 simulator OS 7
Contributor
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

http://postimage.org/image/z22ws5rxh/

 

That is what I am getting, is that not what you want?

Contributor
Posts: 43
Registered: ‎07-22-2012
My Device: curve
My Carrier: syudent

Re: Align 3 Fields one at left,one at center and one at right

try to add another field after them as
ButtonField leftbutton1 = new ButtonField("left");
add(leftbutton1);
you will get aspaces lines try it
Contributor
Posts: 11
Registered: ‎10-14-2012
My Device: Developer
My Carrier: Developer

Re: Align 3 Fields one at left,one at center and one at right

Okay, I know what you mean.

 

The reason why that is there is because we assigned our vertical field managers to use all the height of the display. If you want to add another field to the display, you will need to modify the grid that we created and insert the field into the correct space.

 

I can help you do that if you provide some more information as to where you want it.