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
Highlighted
Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus
Accepted Solution

LabelField text position

Hi, I have created fat labelfields by adding paddings on them and have managed to align the text to middle via DrawStyle.HCENTER.

 

I am wondering how I can make them vertically centered as VCENTER does not do anything.

 

I can think of one way to achieve what I want - by adding calculated margin to the top but this seems to be a lot more work.

 

Any help will be appreciated!

 

fat labelfield

----------------------------------------------------------
Twitter: @gyubok
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: LabelField text position

Add equal paddings on the top and the bottom. Right now, it seems you have only a bottom padding greater than zero.

 

Why are you saying that adding the top padding is "a lot" more work? You divide the value you are now using for the bottom padding by 2 and set top and bottom padding to that value.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: LabelField text position

Adding padding (or margin) will not allow the text to move to the middle of the labelfield, it will simply add space to the entire labelfield.

 

To correct myself on the initial post, I haven't added any any padding or margin. I made the labelfield fat by overriding preferredheight, width, and layout.

 

It's weird because using DrawStyle.HCENTER will center the text position within the given horizontal space of the labelfield but DrawStyle.VCENTER will not center vertically.

----------------------------------------------------------
Twitter: @gyubok
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: LabelField text position

I suspect that the main problem is in your layout code. Try creating the field with USE_ALL_WDITH | USE_ALL_HEIGHT in addition to HCENTER and VCENTER and calling super.layout with the width and height calculated by you rather than the ones passed. And do not call setExtent after super.layout.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: LabelField text position

I solved the problem by positioning the text manually (overriding the graphics).

 

Thank you for your help!

----------------------------------------------------------
Twitter: @gyubok
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: LabelField text position

Overriding paint? Then you should have abandoned LabelField and extended Field instead. This would be a much safer approach.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 660
Registered: ‎10-08-2009
My Device: Bold 9900
My Carrier: Telus

Re: LabelField text position

Paint, sorry. Yes, I'm switching to field as I type Smiley Happy

----------------------------------------------------------
Twitter: @gyubok