BlackBerry Forums Support Community               

Closed Thread
LinkBack Thread Tools
Old 04-18-2007, 11:59 PM   #1 (permalink)
Thumbs Must Hurt
Join Date: Feb 2007
Model: 8100
Carrier: T-Mobile
Posts: 54
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default What in the world am I doing wrong? This can't be this difficult!

Please Login to Remove!

Hi all,

I'm trying to do something "simple"
I'm trying to center a LabelField within a HorizontalFieldManger.

I've overridden the HorizontalFieldManagers sublayout method to explicitly set the width of the field to 200 px.

Here's the result.

Below is the code, there's nothing else on the screen.

Any and all help MUCH appreciated !

HorizontalFieldManager hfm = new HorizontalFieldManager()
    int cellWidth = 200;

    protected void sublayout(int maxWidth, int maxHeight)
             super.sublayout(cellWidth, maxHeight);
             setExtent(cellWidth, getExtent().height);

   public int getPreferredWidth()
           return cellWidth;

   public void subpaint(Graphics graphics)

LabelField lf = new LabelField("CENTERED LABEL",


Last edited by mdwheaton : 04-19-2007 at 12:05 AM.
Old 04-23-2007, 10:34 AM   #2 (permalink)
Talking BlackBerry Encyclopedia
Join Date: Oct 2006
Model: 7103
Carrier: Verizon
Posts: 259
Post Thanks: 0
Thanked 0 Times in 0 Posts

Try, in the paint/subpaint methods, rather than accessing the super's paint/subpaintMethod, to utilize the graphics drawText method, handling the x,y coords yourself. Ensure you set the font before for the for the drawtext to work, example:

public void paint(Graphics g) {
		getPreferredHeight(), 0, 0);
		if (style == LabelField.RIGHT)
					.drawText(labelText, getPreferredWidth()
							- labelFont.getAdvance(labelText),
			g.drawText(labelText, 0, 2);
Old 04-24-2007, 07:28 PM   #3 (permalink)
New Member
Join Date: Apr 2007
Carrier: none
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default sublayout may be the answer

Ditto, it does not work if this is the first (or the only) label in manager.
A bug in RIM API for sure.

Since you are not shy to override manager : try standard approach:
in manager.sublayout simply position your field. No paint, subpaint jobs are necessary.

Hope this helps,
Old 04-25-2007, 07:23 AM   #4 (permalink)
Thumbs Must Hurt
Join Date: Jan 2007
Model: 8100
Carrier: Rogers
Posts: 77
Post Thanks: 0
Thanked 0 Times in 0 Posts

Did you try a VerticalFieldManager instead?
Old 08-02-2007, 10:57 AM   #5 (permalink)
Knows Where the Search Button Is
Join Date: Jul 2007
Model: 8800
Carrier: t-mobile
Posts: 44
Post Thanks: 0
Thanked 0 Times in 0 Posts

I dont't know if you can still use a answer on this problem but i run into the same problem. For me the problem was solved by setting the Manager H_CENTER.

HorizontalFieldManager yourManager = new HorizontalFieldManager(Field.FIELD_HCENTER);
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

10K Ohm Potentiometer
10K Ohm Potentiometer picture16 VTG AB/JU-1031 TYPE J/USA/Wirewound Potentiometer/Pots RADIO HAM PARTS
16 VTG AB/JU-1031 TYPE J/USA/Wirewound Potentiometer/Pots RADIO HAM PARTS  pictureCTS 137 Potentiometer T-217 8030
CTS 137  Potentiometer T-217 8030 pictureSTACKPOLE Potentiometer 304 72 10 39 7853
STACKPOLE  Potentiometer 304 72 10 39 7853 pictureOAK Potentiometer
OAK  Potentiometer  picture

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