Tushar
Tushar

Reputation: 5955

Set the width of label field in Blackberry

How can I set the width of a label field width in Blackberry?

Upvotes: 1

Views: 3949

Answers (2)

Shreyash Mahajan
Shreyash Mahajan

Reputation: 23606

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.

Upvotes: 1

cjp
cjp

Reputation: 313

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

Upvotes: 5

Related Questions