Visit Sponsor

Written by 6:17 pm Core Java

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);
        }
    }
Visited 5 times, 2 visit(s) today
Close