Search code examples
textjava-memidplcdui

Wrap text on Canvas in J2ME


I am going to develop j2me application. I want to know, how i can wrap text on canvas according to screen width size in J2ME.


Solution

  • You need to calculate the width of the string to be drawn yourself and start a new line (split the string) each time you reach the max width of the canvas.

    void paint(Graphics _g) {
      String t = "text to draw";
      int px_consumed = _g.getFont().substringWidth(t, 0, t.length())}
    }