Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Trusted Contributor
Posts: 138
Registered: ‎04-19-2012
My Device: No
My Carrier: Nokia

How to set background color of labelfield in full witdh

Hello guys,

                       I want to set background color of labelfield.

                       but my code is working only for labelfield width.

                       and i want that background color should contain

                       all width of screen.....



LabelField display = new LabelField("Loading Cnfiguration..........")

public void paint(Graphics graphics) {

Posts: 23
Registered: ‎08-09-2010
My Device: 9800
My Carrier: Airtel

Re: How to set background color of labelfield in full witdh

Overide layout method in your custom label field class. Use the below sample.


protected void layout(int width, int height) {
		setExtent(Math.min(width, getPreferredWidth()), Math.min(height,getPreferredHeight()));

public int getPreferredHeight() {
		return height;

public int getPreferredWidth() {
		return Display.getWidth();


New Developer
Posts: 60
Registered: ‎09-23-2011
My Device: Blackberry
My Carrier: Blackberry Developer

Re: How to set background color of labelfield in full witdh



First you set the height and width of labelfield and the set the button color.

Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to set background color of LabelField in full width

What you are seeing is the LabelField working as designed.  By default, it will only take up the space it requires.  So you need to tell it to use the full width, which you can do using the style USE_ALL_WIDTH. 


LabelField display = new LabelField("Loading Configuration..........", LabelField.USE_ALL_WIDTH)


This will not position your text in the center.  If you want to do that you need to another style as well - a DrawStyle style.  Ask if you need help with this.