BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-08-2006, 03:41 PM   #1
richever
Thumbs Must Hurt
 
Join Date: Jan 2006
Location: San Francisco, CA
Model: 7290
Carrier: Cingular
Posts: 53
Default Vertical centering text in LabelField

Please Login to Remove!

I'm trying to center vertically text I'm adding to a LabelField. The problem is that none of the style constants I've tried (Field.FIELD_VCENTER, DrawStyle.VCENTER etc.) have any affect on the text position. Can anyone help?

Thanks!

Rich
Offline  
Old 05-09-2006, 07:47 AM   #2
djphillips
Knows Where the Search Button Is
 
Join Date: Apr 2006
Model: 7100
Posts: 17
Default Clarification

What do you mean by "vertically centered"? Do you mean centered vertically on the visible screen or within the manager?

My guess here is that you want to extend the Label class and override the layout() and/or getPreferredHeight() functions to give yourself enough space to center things vertically. The Layout class will try to make its height as small as possible to fit in all the text. So, if it can be displayed on 3 lines, it will take around 3 times the font height. This means there is no room to move things up or down in the layout. If you modify layout() to set the height larger, the Label may just correctly draw everything vertically centered. I have to admit, I've never tried this though.

derek
Offline  
Old 05-09-2006, 11:27 AM   #3
eradis
Talking BlackBerry Encyclopedia
 
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Posts: 221
Default

Try this:

Code:
public class CustomLabelField extends LabelField{
        public CustomLabelField (String name){
                super(name,HCENTER | ELLIPSIS );                    
        }        
        public int getPreferredWidth(){
                return Graphics.getScreenWidth()/3;
        }
}
The HCENTER style handles the text alignment - centers it.
Offline  
Old 05-10-2006, 04:37 PM   #4
richever
Thumbs Must Hurt
 
Join Date: Jan 2006
Location: San Francisco, CA
Model: 7290
Carrier: Cingular
Posts: 53
Default

Perhaps I didn't word my original post correctly. I'll try again.

I have a number of LabelFields that are part of a HorizontalFieldManager. Each of these LabelFields are about 24 pixels wide and 16 pixels high. I've reduced the font size of the text that I add to each label using the setText() method, causing the text in the LabelFields to 'float' to the top of the field. That's what I mean by vertical: you know, up and down? The default, left justafied text placement looks great. It's the vertical centering of the text I'm concerned with.

I've tried every style in DrawStyle and Field that even contains a 'V' but applying them has no affect. DrawStyle.HCENTER works great, by the way, if you wanted to center text horizontally. Not sure why DrawStyle.VCENTER doesn't do the same. Any help much appriciated.

Rich
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M picture

iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M

$4.99



OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet  picture

OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet

$2.99



10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord picture

10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord

$4.98



10 Feet/3M For iPhone 13 12 11 PRO MAX MINI  X XR XS 8 7 Fast Charging USB Cable picture

10 Feet/3M For iPhone 13 12 11 PRO MAX MINI X XR XS 8 7 Fast Charging USB Cable

$5.00



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$31.90







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.