BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Fixed width button trick not working correctly... (http://www.blackberryforums.com/showthread.php?t=169705)

patokike 01-09-2009 11:35 PM

Fixed width button trick not working correctly...
 
I have tested the trick given here
BlackBerry Fixed Width ButtonField (also here http://www.blackberryforums.com/deve...set-width.html)

... plus adding a Style so can be centered
my idea was to make it 30 pixels less than the screen width
so.. I have this
Code:

public class FixedWidthButtonField extends ButtonField{
    private int width;
 
    FixedWidthButtonField( String label, int Width){
        super( label, ButtonField.FIELD_HCENTER);
        width = Width;
    }
 
    public int getPreferredWidth(){
        return width;
    }
}

and in the screen
Code:

...
FixedWidthButtonField _bf = new FixedWidthButtonField("Test", Display.getWidth() - 30);
add(_bf);
...

with this I get the button centered, by the text in it isnīt centered!!

http://img55.imageshack.us/img55/272...problemyn3.jpg

Iīm using JDE 4.5.0
any ideas?? :smile:

Thanks in advance...

Dougsg38p 01-10-2009 08:41 PM

Field.FIELD_HCENTER only centers the Field object within the manager.

To center the text, add DrawStyle.HCENTER to the style parameter.

patokike 01-10-2009 11:04 PM

Thanks Dougsg38p
but your solution doesn't change anything. I'm still seeing the text aligned to the left in the button :-(

Do you think it has something to do with my JDE version?

Thanks for your time.

Swiebertje 06-03-2009 08:48 AM

Did you find a solution for this?

ddragoste 10-06-2009 11:47 AM

If it still matters ....
To center the text in the button,
override paint in FixedWidthButtonField with something like:

Font font = Font.getDefaultFont();
int textWidth = font.stringWidth(getLabel());
g.drawText(getLabel(), (width - textWidth) / 2, 0);


All times are GMT -5. The time now is 12:14 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.