Text doesn't fit properly with Custom LabelField in Blackberry

I am using Custom LabelField in my application. It works fine with small fonts when I increase the size of a font that it will not display properly. Here you can see it in this image.

enter image description here

You can see that only half of the text is displayed on the image. How can I overcome this?

Here I give my code for a custom LabelField. Please tell me what I am doing wrong.

public class CustomLabelField extends Field  
{  
    private String label;  
    private int fontSize;
    private int foregroundColor;  
    private int backgroundColor;  
    public CustomLabelField(String label, int fontSize, int foregroundColor,  
                     int backgroundColor,long style)  
    {  
        super(style);  
        this.label = label;  
        this.foregroundColor = foregroundColor;  
        this.backgroundColor = backgroundColor;  
        this.fontSize = fontSize;
    }  

   protected void layout(int width, int height) {  

       setExtent(width, getFont().getHeight());  


   }  

    protected void paint(Graphics graphics) {  

       graphics.setBackgroundColor(backgroundColor);  
       graphics.clear();  
       graphics.setFont(setMyFont());  
       graphics.setColor(foregroundColor);  
       graphics.drawText(label, 0, 0, (int)(getStyle()& DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK),getWidth() - 6);  
   }  

   // Get font for the label field  
   public Font setMyFont()  
   {  
     try {  
         FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");  
         Font appFont = alphaSansFamily.getFont(Font.PLAIN, fontSize, Ui.UNITS_pt);  
         return appFont;  

    } catch (ClassNotFoundException e) {  
        // TODO Auto-generated catch block  
        e.printStackTrace();  
    }  
    return null;  
  }  

}
+3
source share
2 answers

layout . , . , :

protected void layout(int width, int height) {  

    int fieldHeight = Ui.convertSize(fontSize, Ui.UNITS_pt, Ui.UNITS_px);
    setExtent(width, fieldHeight);  
}  

.

+3

CustomLabelField LabelField? , (, , ..) LabelField, .

Field, setFont(Font). . .


CustomLabelField:
class CustomLabelField extends LabelField {
    private int foregroundColor;
    private int backgroundColor;

    public CustomLabelField(String label, int foregroundColor,
            int backgroundColor, long style) {
        super(label, style);
        this.foregroundColor = foregroundColor;
        this.backgroundColor = backgroundColor;
    }

    protected void paint(Graphics graphics) {
        graphics.setBackgroundColor(backgroundColor);
        graphics.clear();
        graphics.setColor(foregroundColor);
        super.paint(graphics);
    }
}


:
class MyScreen extends MainScreen {

    public Font getMyFont(int fontSize) {
        try {
            FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
            return alphaSansFamily.getFont(Font.PLAIN, fontSize, Ui.UNITS_pt);
        } catch (Exception e) {
        }
        return null;
    }

    public MyScreen() {
        CustomLabelField clf = new CustomLabelField(
                    "Main",
                    Color.WHITE,
                    Color.BLACK,
                    LabelField.ELLIPSIS);

        // Font setup
        clf.setFont(getMyFont(20));

        add(clf);
    }
}
+3

All Articles