Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 18:39, 25 October 2013 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to display rotated text in Java ME

From Wiki
Jump to: navigation, search
Article Metadata
Created: bogdan.galiceanu (04 Sep 2008)
Last edited: lpvalente (25 Oct 2013)

This article provides a method for displaying rotated text on a canvas in Java ME. The idea is to create an empty image, write the text on it and display it, rotated.

import javax.microedition.lcdui.*;
public class MyCanvas extends Canvas {
public void paint(Graphics g) {
//The text that will be displayed
String s="java";
//Create the blank image, specifying its size
Image img=Image.createImage(50,50);
//Create an instance of the image's Graphics class and draw the string to it
Graphics gr=img.getGraphics();
gr.drawString(s, 0, 0, Graphics.TOP|Graphics.LEFT);
//Display the image, specifying the rotation value. For example, 90 degrees
g.drawRegion(img, 0, 0, 50, 50, Sprite.TRANS_ROT90, 0, 0, Graphics.TOP|Graphics.LEFT);


Rotated text.JPG

This page was last modified on 25 October 2013, at 18:39.
39 page views in the last 30 days.