Blackberry: custom LabelField

It is needed sometimes to customize the default fields as per requirements. So creating custom fields are easy, you can customize such as set text color of Label as per your need and change graphics in paint method to reflect required look and feel, as following:




// Custom Label field used in LoginScreen
public class CustomLabelField extends LabelField
{
	private int _txtColor;
	public CustomLabelField(String label)
	{
		super(label, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.RIGHT);
		_txtColor = Color.DARKBLUE;
		setPadding(new XYEdges(2,15,0,0));
	}
	public CustomLabelField(String label,long style)
	{
		super(label,style);
		_txtColor = Color.DARKBLUE;
		setPadding(new XYEdges(2,15,0,0));
	}
	public CustomLabelField(String label,int color)
	{
		super(label, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH | LabelField.RIGHT);
		_txtColor = color;
		setPadding(new XYEdges(2,15,0,0));
	}

	protected void paint(Graphics g) {
		// text is displayed in white
		//g.setColor(Color.WHITE);
		g.setColor(_txtColor);
		super.paint(g);
	}

	protected void layout(int width, int height) {
		// occupies 5/12 (approx. half) of the screen width
		super.layout(Display.getWidth()*4/12, height);
		//setExtent(width, height)
	}
}


Advertisements

About M Moniruzzaman
A passionate software engineer, have been developing applications on various platforms such as Android, iPhone, .Net (C#) technologies and web based ASP.NET, PHP, JavaScript, jQuery technologies for more than 10 years. Especially I have expertise on developing applications for Android and iPhone, as well as service oriented, client-server based applications where clients will be reside on Android/iPhone that communicate with WCF(.NET) service hosted on server. I have completed certification in Microsoft Certified Professional Developer (MCPD) on .Net 4 . I have completed my graduation in -- B.Sc. (Engineering) in Computer Science and Engineering, ShahJalal University of Science and Technology, Bangladesh. Thanks, M. Moniruzzaman (Zaman)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: