BlackBerryForums.com : Your Number One BlackBerry Community      

»Sponsored Links




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

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
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

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

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
   
  (#3 (permalink)) Old
eradis Offline
Talking BlackBerry Encyclopedia
 
Posts: 221
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Default 05-09-2006, 12:27 PM

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.
   
  (#4 (permalink)) Old
richever Offline
Thumbs Must Hurt
 
Posts: 53
Join Date: Jan 2006
Location: San Francisco, CA
Model: 7290
Carrier: Cingular
Default 05-10-2006, 05:37 PM

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
   
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On






Copyright © 2004-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1