Welcome!

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

Reply
Highlighted
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

drawing a text on multiple lines in one row of Listfield

I want that text that i am getting from SampleClass.getText should be Displayed on 2 line.

here is the code:

public void drawListRow(final ListField list, final net.rim.device.api.ui.Graphics g, final int index, final int y, final int w)
{

g.drawText(SampleClass.getText(), 20, y+10, 0, w);

}

Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: drawing a text on multiple lines in one row of Listfield

I think you need to write a custom class. You may check this : multiple text in a row

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: drawing a text on multiple lines in one row of Listfield

no need for a custom class, listifield is fine.

if you want two lines, call setRowHeight after creating the listfield and set the approrpiate height, for example 2*getFont().getHeight()

draw the first line with unmodified y, the second with y+getFont().getHeight() (or the appropriate value if you used something else).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800
My Carrier: idea

Re: drawing a text on multiple lines in one row of Listfield

The following link might helps you

http://supportforums.blackberry.com/t5/Java-Development/Can-drawText-wrap-text-into-multiple-lines/m...
*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Developer
Posts: 255
Registered: ‎05-03-2012
My Device: 9930
My Carrier: Vodafone

Re: drawing a text on multiple lines in one row of Listfield

private Vector wrap (String text, int width)
{
Vector result = new Vector ();
if (text ==null)
return result;

boolean hasMore = true;

// The current index of the cursor
int current = 0;

// The next line break index
int lineBreak = -1;

// The space after line break
int nextSpace = -1;

while (hasMore)
{
//Find the line break
while (true)
{
lineBreak = nextSpace;
if (lineBreak == text.length() - 1)
{
// We have reached the last line
hasMore = false;
break;
}
else
{
nextSpace = text.indexOf(' ', lineBreak+1);
if (nextSpace == -1)
nextSpace = text.length() -1;
int linewidth = this.getFont().getAdvance(text,current, nextSpace-current);
// If too long, break out of the find loop
if (linewidth > width)
break;
}
}
String line = text.substring(current, lineBreak + 1);
result.addElement(line);
current = lineBreak + 1;
}
return result;
}
public void drawListRow(ListField lf, Graphics g, int row, int y, int width) {

String sh = "whatever content you want";
Vector lines = wrap(sh, textwidth);
for (int i = 0; i < lines.size(); i++)
{
int liney = y + (i * this.getFont().getHeight());
g.drawText((String)lines.elementAt(i), 0 ,liney,TOP | LEFT | DrawStyle.ELLIPSIS, textwidth);

}
}



Not working