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.

Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone
Accepted Solution

Drawing RoundRect shape of a customLabel does not provide roundRect shape


I am creating a Custom Label field that has been created successfully.


Now after that In order to have a round shape for that label in paint(Graphics graphics)   I am drawing a roundRect and then further label content( an image and and a textString) over it.


Yes I can also have label shape round using setBorder(RoundBorder) method (I tried it and thats working ) but I was trying it as follows .


public class CustomField extends Field {

	private String mLabelText = null;
	private int mForegroundColor = 0;
	private int mBackgroundColor = 0;
	private Bitmap mBitmap = null;

	public CustomField(long style, String iLabelText, int iForegroundColor,
			int iBackgroundColor) {
		mLabelText = iLabelText;
		mForegroundColor = iForegroundColor;
		mBackgroundColor = iBackgroundColor;

	public CustomField(Bitmap iBitmap, long style, String iLabelText,
			int iForegroundColor, int iBackgroundColor) {
		this(style, iLabelText, iForegroundColor, iBackgroundColor);
		mBitmap = iBitmap;

	protected void layout(int width, int height) {
		if ((getStyle() & Field.USE_ALL_WIDTH) == Field.USE_ALL_WIDTH) {
			setExtent(width, Math.min(height, getPreferredHeight()));
		} else {
					Math.min(height, getPreferredHeight()));

	protected void paint(Graphics graphics) {

		graphics.drawRoundRect(0, 0, getWidth(), getHeight(),
				20	, 20);

graphics.setBackgroundColor(mBackgroundColor); graphics.clear(); graphics.setFont(Font.getDefault().derive(Font.SANS_SERIF_STYLE, 25, Ui.UNITS_px, Font.ANTIALIAS_NONE, Font.COLORED_OUTLINE_EFFECT)); graphics.setColor(mForegroundColor); if (mBitmap != null) { int textHeight = (getHeight() - getFont().getHeight()) / 2; int imageHeight = (getHeight() - mBitmap.getHeight()) / 2; graphics.drawBitmap(0, imageHeight, mBitmap.getWidth(), mBitmap.getHeight(), mBitmap, 0, 0); graphics.drawText(mLabelText, mBitmap.getWidth(), textHeight, DrawStyle.ELLIPSIS, getWidth() - mBitmap.getWidth()); } else { graphics.drawText(mLabelText, 0, 0, DrawStyle.ELLIPSIS, getWidth()); } } public int getPreferredHeight() { if (mBitmap != null) { return Math.max(mBitmap.getHeight(), getFont().getHeight()); } else { return getFont().getHeight(); } } public int getPreferredWidth() { int width = getFont().getAdvance(mLabelText); if (mBitmap != null) { width += mBitmap.getWidth(); } return width; } }


For creating label I am using second constructor(one with a Bitmap content);


Can any body Please tell where am I making mistake ? I did tried a range of values for arcWidth and arcHeight params of drawRoundRect() method but no round rectangle (plain rectangular  shape ).




Always Success
Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Drawing RoundRect shape of a customLabel does not provide roundRect shape

OK I got it , problem was in paint() method


I was drawing Rect before calling clear() .  Now i got the Label's rounded shape.


can we set backgroundcolor to drawn RoundRect instead of field(graphics object) ?

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

Re: Drawing RoundRect shape of a customLabel does not provide roundRect shape

[ Edited ]

Great, can you mark this as solved then - try Help at the top is you don't know how to do this.


And no, the background color is an attribute of the graphics Object.  You can fillRect with the background color you want before you do a drawRoundRect if you want.


BTW, in my experience drawRoundRect is not very pretty.  You get better curves if you use an image, which has various alpha values (transparency) which gives a better impression of a curve. 

Posts: 80
Registered: ‎09-03-2012
My Device: 9810
My Carrier: Vodafone

Re: Drawing RoundRect shape of a customLabel does not provide roundRect shape

Thanks peter for the reply


Yes I did it by mistake. It happened because I thought of creating rounded shape for the Customlabel at last.


Ok , I tried fillRoundRect instead of drawRoundRect. Yes its now as I needed. Thanks


Ok I will also try to use image

Always Success