Ho开发者_运维问答w can I set the width of a label field width in Blackberry?
Well if you just want something quick and dirty, this should do the job:
LabelField lField = new LabelField("text")
{
protected void layout(int width, int height) {
super.layout(width, height);
this.setExtent(HARD_CODED_WIDTH, this.getHeight());
}
};
But the right way to do it is choose (or write) a layout manager that does what you want with some flexibility to account for different screen sizes and other things. RIM has a few decent samples up on writing your own manager. Search for JustifiedEvenlySpacedHorizontalFieldManager. Or take a look at thinking blackberry: http://www.thinkingblackberry.com/archives/116
cjp's answer is corrent but i am adding more in to it.
If your text length is more and getting cut in with above code then you can do like below code:
LabelField lField = new LabelField("text")
{
protected void layout(int width, int height) {
super.layout(width, height);
this.setExtent(HARD_CODED_WIDTH, this.getHeight());
}
public int getPreferredWidth() {
return HARD_CODED_WIDTH;
}
};
Above code will not cut the text if the text length is more then the width you have define. And in that case the text get to the next line.
Hope you got the point.
精彩评论