In a previous post I linked the ColoredLabelField.java class. This class has replaced all of my LabelFields. I forget where I got the details from (probably stack overflow) though its been changed since then. Either way, this is how you change font color of a UI element on BlackBerry. Figured this is a pretty basic thing that I may as well make easier to find.

ColoredLabelField.java

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package ca.dftr.calendar.ui.components;
 
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.LabelField;
 
/**
 * Creates a label field with a custom font color
 * @author deforbes, ...
 */
public class ColoredLabelField extends LabelField {
 
	/**
	 * ColoredLabelField constructor
	 * @param text Text to be contained within the field
	 * @param style LabelField modifiers (i.e. ColoredLabelField.FIELD_LEFT | ColoredLabelField.HIGHLIGHT_SELECT)
	 */
	public ColoredLabelField(String text, long style) {
		super(text, style); 
	}
 
	/**
	 * ColoredLabelField color constructor
	 * @param text Text to be contained within the field
	 * @param style LabelField modifiers (i.e. ColoredLabelField.FIELD_LEFT | ColoredLabelField.HIGHLIGHT_SELECT)
	 * @param color Font color (i.e. Color.BLACK)
	 */
	public ColoredLabelField(String text, long style, int color) {
		super(text, style);
		_fontColor = color;
	}
	private int _fontColor = -1;
 
	/**
	 * Set the LabelFields font color
	 * @param fontColor Font's Color
	 */
	public void setFontColor(int fontColor) {
		_fontColor = fontColor;
	}
 
	/**
	 * Get Font's Color
	 * @return Color bit.
	 */
	public int getFontColor(){
		return _fontColor;
	}
 
	protected void paint(Graphics graphics) {
		if (-1 != _fontColor)
			graphics.setColor(_fontColor);
		super.paint(graphics);
	}
}