如何在黑莓中使用自定义标签字段以多行显示文本?当我使用以下代码时,我可以显示具有所需字体大小的标签,但是问题是当范围的宽度受到限制时,文本会被截断并且不完全显示,标签的其余部分也不会显示在下一行。
任何帮助在这里表示赞赏。
以下是我的自定义标签字段代码。
public class GrayBgLabelField extends LabelField {
private int width = Display.getWidth();
private int height = 40;
private String label;
private Font font;
public GrayBgLabelField(){
super();
}
public GrayBgLabelField(String label, int fieldWidth){
super(label, 0 );
this.label = label;
width = fieldWidth;
}
public GrayBgLabelField(String label, int fieldWidth , long style){
super( label, style );
this.label = label;
width = fieldWidth;
}
public GrayBgLabelField(String label, int fieldWidth , int fieldHeight){
this(label,fieldWidth);
this.label = label;
height = fieldHeight;
}
public GrayBgLabelField(String label, int fieldWidth , int fieldHeight, long style){
super( label, style );
this.label = label;
width = fieldWidth;
height = fieldHeight;
}
protected void layout( int maxWidth, int maxHeight)
{
super.layout( width, height);
setExtent( width, height);
}
protected void paint(Graphics g) {
if(font !=null){
g.setFont(font);
}
if (label.length() != 0) {
g.drawText(label, width/30, height/4);
}
g.setColor(Color.BLACK);
}
public void setFont(int f){
font = this.getFont().derive(f);
}
public void setFont(Font font){
this.font = font;
}
protected void paintBackground(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0xF5F6F8); // Gray-DDDDDD color code.
g.fillRect(0, 0, getWidth(), getHeight());
} finally {
g.setColor(oldColor);
}
}
}