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 !

Code:
		
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)
   {
        graphics.setBackgroundColor(Color.BISQUE);
        graphics.clear();
        super.subpaint(graphics);
    }
};

LabelField lf = new LabelField("CENTERED LABEL",
 LabelField.FIELD_HCENTER);

hfm.add(lf);
add(hfm);

Last edited by mdwheaton : 04-19-2007 at 12:05 AM.
Offline  
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
Default

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:

Code:
public void paint(Graphics g) {
		getPreferredHeight(), 0, 0);
		g.setColor(fontTextColor);
		g.setFont(labelFont);
		if (style == LabelField.RIGHT)
			g
					.drawText(labelText, getPreferredWidth()
							- labelFont.getAdvance(labelText),
							2);
		else
			g.drawText(labelText, 0, 2);
	}
Offline  
Old 04-24-2007, 07:28 PM   #3 (permalink)
New Member
 
Join Date: Apr 2007
PIN: N/A
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,
Nik
Offline  
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
Default

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

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);
Offline  
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-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.