I am making a custom Field representing an image and a label near it.
I am drawing the image by graphics.drawBitmap(...)
Nw for the text, I am using graphics.drawText(String, x, y);
but if the text it bigger than the display, it doesn't return to the line. I tried to add \n
but that didn't solve the problem.
How can I draw a text that can expand on several lines?
Thanks,
As this answer says :
The
drawString
method does not handle new-lines, so isdrawText
You'll have to split the string on new-line characters yourself and draw the lines one by one with a proper vertical offset.See that answer for details.
I found a solution to the problem. You can find it below for those who are interested in this question:
You can use AttributedCharacterIterator,TextLayout and LineBreakMeasurer classes as explained in this Java Tutorial.