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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

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.