Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

A Field’s font is displayed incorrectly when set in the paint method

by Retired ‎02-16-2010 03:34 PM - edited ‎09-16-2010 02:39 PM (1,506 Views)



This article applies to BlackBerry® devices based on Java™.




The Field.setFont(Font font) method should be used to set or change the font used by any field in the BlackBerry API set. A font should not be set or changed within the Field’s paint method. The following code example will NOT work:



LabelField myField = new LabelField("Hi there.")
public void paint(Graphics graphics)




The Field’s setFont method should be used in the following way:



LabelField myfield = new LabelField("Hi there.")


This allows for the font used within a specific field to be set. To change a font for the entire application, the Font.setDefaultFont(Font font) method should be used. For an example, see here.


Note: This does not mean that the Graphics.setFont method should not be used. If you are performing custom drawing actions using the Graphics class on a custom Screen or Field, the setFont method can be used to change the font that is being drawn. Graphics.setFont should not be used to change the font being drawn by existing fields contained within the BlackBerry API set. Under this circumstance, the Field.setFont method should be used.

Users Online
Currently online: 43 members 1,665 guests
Please welcome our newest community members: