Reputation: 1885
I have an issue with Blackberry 5 & 6 Os on simulator The label field becomes clumsy when i set the font the same runs fine in Blackberry 7
here is my sample code
LabelField _lblTitle3 =
new LabelField(offerStatus,
USE_ALL_WIDTH | Field.FIELD_VCENTER |
LabelField.ELLIPSIS | Field.NON_FOCUSABLE) {
protected void drawFocus(Graphics graphics, boolean on) {
};
protected void paintBackground(Graphics graphics) {
String offerStatus = _offerObj.getCategoryStatus();
int color;
if (offerStatus.equalsIgnoreCase("Saved"))
color = Color.BLUE;
else if (offerStatus.equalsIgnoreCase("Accepted!"))
color = Color.GREEN;
else
color = Color.BLACK;
if (_isFocus) {
graphics.setColor(Color.WHITE);
} else {
graphics.setColor(color);
}
super.paint(graphics);
};
};
Font myFont = Font.getDefault();
FontFamily typeface = FontFamily.forName("Times New Roman");
int fType = Font.BOLD
int fSize = 12
myFont = typeface.getFont(fType, fSize);
_lblTitle3.setFont(myFont);
Image is below
Upvotes: 0
Views: 52
Reputation: 31045
What are you trying to do? Just change the font color?
If so, you probably don't want to override paintBackground()
.
Inside your implementation of paintBackground()
, you are calling super.paint()
. I'm not sure what that would do, but it wouldn't surprise me if that was wrong.
paint()
and paintBackground()
are two separate things.
If you just want to change the font color, depending on the text and the focus state, just put that logic in the paint()
method, and leave paintBackground()
alone (don't override it).
Also, when you change the Graphics
context, to do things like set a new color, it's usually safer to store the old color first, and reset it later. Something like this:
protected void paint(Graphics graphics) {
int oldColor = graphics.getColor();
String offerStatus = _offerObj.getCategoryStatus();
int color;
if (offerStatus.equalsIgnoreCase("Saved"))
color = Color.BLUE;
else if (offerStatus.equalsIgnoreCase("Accepted!"))
color = Color.GREEN;
else
color = Color.BLACK;
if (_isFocus) {
graphics.setColor(Color.WHITE);
} else {
graphics.setColor(color);
}
super.paint(graphics);
graphics.setColor(oldColor);
};
Upvotes: 3