• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Display Using DrawText

 
Ronakkumar Patel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have one problem in displaying text in Canvas using DrawText function.
My couple of strings are larger then 2 to 3 lines. And in DrawText '\n' is not supported.
Is there any way or any function in which i just put my string and it will dispaly in well manner if it is two long.
Means it will atomatically create a new line for the string when ever it finds that string is big enough to come in to emulator display.

Thanks in advance
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I would hope so, but it is really just drawing. I had the same issue and had to figure out how to make what I wanted to say in less words.

The only other way is to make some kind of method that takes in the String, the width of each letter, the width of the Screen Size and calculate how many letters can fit on a line, then return an array of Strings for each element being one line, then in your paint method, paint the lines of text, remembering to increase the "point" so that they are on seperate lines. By Point I mean by the "anchor" that is used and the x,y coordinate of that anchor and how it relates to the height of the text.

Sorry. If you find a better way, maybe J2ME Polish has that way, let us know.

Mark
 
Ronakkumar Patel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey i got the solution.
I got a one Wordwap.java file , which does this. If u need let me know.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, where did you find it?

Mark
 
Ronakkumar Patel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The class file



Putting Code Tags around the code so we can read it.
[ July 13, 2005: Message edited by: Mark Spritzler ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it returns the position/index within the String that would fit on the next line. Then the next call to the next method will get the next position/index of the next line, until there is no more letters, in which the next method returns -1.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic