Monday, September 12, 2011

Blackberry Color Label Field

Following code example use for create custom color label filed.


import net.rim.device.api.i18n.ResourceBundleFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;

public class ColorLableField extends LabelField{
private int color = 0x000000;
public ColorLableField(String text){
super(text);
}
public ColorLableField(Object text, int offset, int length, long style){
super(text, offset, length, style);
}
public ColorLableField(Object text, long style){
super(text, style);
}
public ColorLableField(ResourceBundleFamily rb, int key){
super(rb, key);
}

//Set the color of the text in this field
public void setColor(int newColor){
color = newColor;
}

//Set the foreground color and then call paint method of the parent class
public void paint(Graphics graphics){
graphics.setColor(color);
super.paint(graphics);
}
}

public final class MyScreen extends MainScreen{

public MyScreen()
{
setTitle("MyTitle");
ColorLableField lbl = new ColorLableField("this is text");
lbl.setColor(Color.RED);
this.add(lbl);
}
}