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
Posts: 19
Registered: ‎07-22-2008
My Device: Not Specified
Accepted Solution

How to center field in VirtualFieldManager?

Hello,

 

I need center ButtonField in VerticalFieldManager. I have used this, but the button is aligned to the left.

 

VerticalFieldManager  v1Manager = new VerticalFieldManager();

 

ButtonField btn = new ButtonField("Button A", ButtonField.FIELD_HCENTER | ButtonField.CONSUME_CLICK);
btn.setChangeListener(this);
           

v1Manager.add(btn);            

 

 

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: How to center field in VirtualFieldManager?

Add " | DrawStyle.HCENTER" in that button field creation..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Highlighted
Developer
Posts: 173
Registered: ‎08-20-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

Is there anything else in that VFM? The VFM will only stretch as wide as the widest field it manages. If you create an instance of the field below and add it to your VFM do you get the desired affect?

 

public class HozBuffer extends Field { private final int BUFFER_HEIGHT = 1; public HozBuffer() { super(); } protected void paint(Graphics g) { g.setColor(0xFFFFFF); g.clear(); } public int getPreferredHeight() { return BUFFER_HEIGHT; } protected void layout(int width, int height) { setExtent(Graphics.getScreenWidth(), BUFFER_HEIGHT); } }

 

Developer
Posts: 178
Registered: ‎07-29-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

or you could use Field.USE_ALL_WIDTH in the VFM.
New Developer
Posts: 19
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

and if also needs to center vertically?

 

Thanks

Developer
Posts: 173
Registered: ‎08-20-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

I have never managed to use USE_ALL_WIDTH with good results but that may be due to the version of devices I am running apps on, 4.2.2 mainly. When you say you wish to align it vertically in relation to what? The whole screen or just the VFM?
New Developer
Posts: 19
Registered: ‎07-22-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

yes, only just the VFM.
Developer
Posts: 173
Registered: ‎08-20-2008
My Device: Not Specified

Re: How to center field in VirtualFieldManager?

You could use FIELD_VCENTER however a VFM will only stretch in height to the sum of heights of fields it manages so would most likely have no effect. FIELD_VCENTER would be mainly used for HFMs. If you are looking to give it some vspace you could use setPadding on the button field or the VFM but be aware of different screen resolutions if you are doing it this way. Hope this helps.
Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: How to center field in VirtualFieldManager?

I think you could use DrawStyle.VCENTER in the creation of the VHM.. Never really tested, but hope that will work..

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Regular Contributor
Posts: 77
Registered: ‎11-03-2009
My Device: 9810 Torch
My Carrier: VIPnet

Re: How to center field in VirtualFieldManager?

You actually must use HORIZONTAL Field Manager.

Here is the code snippet (in case you haven't solved it yet   ):

HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
ButtonField  button = new ButtonField("Button",DrawStyle.HCENTER); 
hfm.add(button);