Tutorials Blackberry Customizing Blackberry LabelField

Customizing Blackberry LabelField

We always prefer to use the standard built-in Label Field class to create user-selectable label styles for our application so we can provide a different look to our application. Here is a piece of code which will give you a good understanding of how LableField can be customized.

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);
            this.setPadding(padding);
        }

        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)
                graphics.setColor(mFontColor);
                super.paint(graphics);
        }
    }
Total
0
Shares
Previous Post
Blackberry Tutorials

Saving Bitmap Image in Blackberry File System

Next Post
Blackberry Tutorials

Printing logs 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