Tutorials Blackberry Custom LabelField in Blackberry

Custom LabelField in Blackberry

Here is a sample code which shows how to customize the LabelField in blackberry. This sample code is generic can be portable to any project. It accepts the String label, long style and also padding.

package com.sample.rim.ui.uicontrols;

import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.LabelField;

public class CustomLabelField extends LabelField {

        public CustomLabelField(Object text, long style) {         
            super(text, style);

        public CustomLabelField(Object text, long style, XYEdges padding) {
            super(text, style);
            this.setPadding(2,5, 2, 5);

        private int mFontColor = -1;
        public void setFontColor(int fontColor) {
            mFontColor = fontColor;

        protected void layout(int width, int height) 
         super.layout(width, getPreferredHeight()+5);
      setExtent(width, getPreferredHeight()+5);

        protected void paint(Graphics graphics) {        
            if (-1 != mFontColor)
Previous Post
Blackberry Tutorials

KeyListener in Blackberry

Next Post
Blackberry Tutorials

How to make mobile application portable for multiple devices in Blackberry

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All