Fonts in MIDP

I am going crazy trying to get fonts to work with MIDP. It appears that I have to extend the StringItem class, override the paint method and do a graphics.setFont - this sounds way too cumbersome - there has to be an easier way.
Don

My screen overrode the Canvas class (instead of Form or List) and overrode the paint method, which is passed a refererence to the graphics object:
public void paint(Graphics g) {
Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
g.setColor(0x00000000);
g.setFont(font);
g.drawString("Hi Mom", getWidth()/2, 2, Graphics.TOP | Graphics.HCENTER);
}

Similar Messages

  • Does somebody know how change the Font in MIDP?

    I have a problem with changeing the size of Font in MIDP.
    Construction Font f = new Font(parametr1, parametr2,parametr3);
    setFont(f); is not working.

    There is no public constructor for javax.microedition.lcdui.Font. Use the static Font.getFont() method to get a different font. Check the API documentation for details.

  • Loading external fonts in midp apps

    hello every body
    my question is can i add external fonts to my midp apps? say for example i want to add andulas.ttf font and want my application to show text in to that font?
    please provide a sample code if you can on how to do that....

    yes i need the font for display purpose. basically i am developing an application that receives an unicode character string upon request and display the content in bengali language. i have installed the Arial Unicode Ms to my machine and edited the .properties file of the default phone from sun wireless toolkit accordingly. Arial Unicode Ms supports my language. i am using StringItem to output my content. but when i am output the content it doesnt change the outcome. it just simpley outputing the unicode string as if it has been passed!!!!
    here goes my code..
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class UnicodeTest extends MIDlet
         private Display display = null;
         private Form fm = null;
         private StringItem si = null;
         private Command exit = null;
         public UnicodeTest()
              display = Display.getDisplay(this);
         public void startApp()
              fm = new Form("My form");
              si = new StringItem("in bengali: ","KixeDUw�k gwvlw hwnwk BxZpwo L�g �gxm xb�dk dt");
              fm.append(si);
              display.setCurrent(fm);
         public void pauseApp()
         public void destroyApp(boolean unconditional)
              notifyDestroyed();
    }the following goes my properties files font part...
    font.default=Arial Unicode MS-plain-10
    font.softButton=Arial Unicode MS-plain-11
    font.system.plain.small: Arial Unicode MS-plain-9
    font.system.plain.medium: Arial Unicode MS-plain-11
    font.system.plain.large: Arial Unicode MS-plain-14
    font.system.bold.small: Arial Unicode MS-bold-9
    font.system.bold.medium: Arial Unicode MS-bold-11
    font.system.bold.large: Arial Unicode MS-bold-14
    font.system.italic.small: Arial Unicode MS-italic-9
    font.system.italic.medium: Arial Unicode MS-italic-11
    font.system.italic.large: Arial Unicode MS-italic-14
    font.system.bold.italic.small: Arial Unicode MS-bolditalic-9
    font.system.bold.italic.medium: Arial Unicode MS-bolditalic-11
    font.system.bold.italic.large: Arial Unicode MS-bolditalic-14
    font.monospace.plain.small: Arial Unicode MS-plain-9
    font.monospace.plain.medium: Arial Unicode MS-plain-11
    font.monospace.plain.large: Arial Unicode MS-plain-14
    font.monospace.bold.small: Arial Unicode MS-bold-9
    font.monospace.bold.medium: Arial Unicode MS-bold-11
    font.monospace.bold.large: Arial Unicode MS-bold-14
    font.monospace.italic.small: Arial Unicode MS-italic-9
    font.monospace.italic.medium: Arial Unicode MS-italic-11
    font.monospace.italic.large: Arial Unicode MS-italic-14
    font.monospace.bold.italic.small: Arial Unicode MS-bolditalic-9
    font.monospace.bold.italic.medium: Arial Unicode MS-bolditalic-11
    font.monospace.bold.italic.large: Arial Unicode MS-bolditalic-14

  • MIDP: Changing Font of Item

    Hi ppl! A q about MIDP.
    Is there any way to change Font of some Item (StringItem for example) that has been appended to lcdui.Form? or the Font of Form itself?
    Thanx.

    The only situation where you can change the font is when painting directly to a Graphics object.
    Only the Graphics class has a setFont() and a getFont() method.
    If you want to use different fonts, you have to develop your own component, or you might find some components developed by specific vendors for specific devices.

  • Bitmap font on J2ME/MIDP devices

    Hi!
    I want to develop an application that can display my own langue on a mobile phone. I have known that there is a posibility to use a bitmap font(new_font.png) but I dont know how we can do with that.
    Does anyone know where can I find some documentation related to that? Or if you have some sample code that can solve my problem, that would be great.
    There is not yet unicode for my langue so it would be hard for me to do it this project.
    Best regards,

    I found an API on the web but don't remember which one - it is not free, though - but it uses the low-level API of MIDP to create those buttons and boxes.

  • [J2ME MIDP 2.0] Alert, how to use fonts and colors?

    good morning,
    does anyone know in which way I can use colors in an alert pop-up?
    I've done my on using the code below. I would like to have text and images centered in the screen display and I would also like to use the colors I'm using in the application I'm writing.
    thx in advice,
    Omar
    private void alertDisplay(String s){   
        Alert a = new Alert("Location set to " + s.toUpperCase());   
        if(s.startsWith("H"))
          a.setImage(hOn);
        else
          a.setImage(oOn); 
        a.setString("Actual Location: " + s.toUpperCase());
        a.setTimeout(2000);
        a.setType(AlertType.INFO);
        Display.getDisplay(this).setCurrent(a);
        Display.getDisplay(this).vibrate(1000);
        Display.getDisplay(this).flashBacklight(1000);
      }

    Hi,
    The way how an Alert looks like cannot be influenced. When setting an image, you cannot indicate where that image should be placed. When setting a certain message text, you cannot influence its colour, its font and its allignment...
    The colour and font properties are theme / skin dependent on your mobile. When switching your mobile to another theme, then you will notice that your Alerts (and Forms and Lists, etc etc...) are coloured (titlebar, command softkeys, textfields) according to that theme.
    Cheers,
    Jasper

  • How to convert PNG image to Vertor Image to make font on Mac

    Hi Mac People,
    I like to create a set of font, and I have made them in a image editing tool, I have FontForge downloaded but decide to use it to convert instead direct design them inside.
    So now I don't know how to convert the PNG image to vector image required by the FontForge, I read some post mentioned Ubuntu has utilities to convert, but I'm not sure OS X has that function too.
    Could anyone let me know how to convert PNG so I can create my fonts?
    If PNG can't, the software can export TIFF or jpeg or similar.
    Please help me, I need make them this few day.
    Thanks everyone for giving me a hand!

    take a look at:
    http://developers.sun.com/techtopics/mobility/midp/articles/picture/

  • Font size and Colr

    Here is a simple program just for demonstration.
    I would like to change the font size and color of this program to SMALL and
    RED respectively(when I install it in my handset, it does not fit in the screen
    properly). I have tried read the Font in the midp api but am not getting it; its just talking
    about I don't know Canvas and such kind of stuff.
    Please could someone just help me with this program just as a demonstration
    so I could know exactly how to go about it. Thanks in advance.
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class AddTwoNum extends MIDlet implements CommandListener
         Display display;
         Form mainForm = new Form("Summation of Numbers");
         TextField firstNum = new TextField("First Number", "", 15, TextField.NUMERIC);
         TextField secondNum = new TextField("Second Number", "", 15, TextField.NUMERIC);
         TextBox sumBox;
         Command exitCommand = new Command("Exit", Command.STOP, 1);
         Command calCommand = new Command("Calculate", Command.SCREEN, 2);
         public AddTwoNum()
         public void startApp() throws MIDletStateChangeException
              display = Display.getDisplay(this);
              mainForm.append(firstNum);
              mainForm.append(secondNum);
              mainForm.addCommand(exitCommand);
              mainForm.addCommand(calCommand);
              mainForm.setCommandListener(this);
              display.setCurrent(mainForm);
         public void pauseApp()
         public void destroyApp(boolean unconditional)
              notifyDestroyed();
         public void commandAction(Command c, Displayable d)
              if (c == exitCommand)
                   destroyApp(true);
              else if (c == calCommand)
                   int first, second, sum;
                   first = Integer.parseInt(firstNum.getString());
                   second = Integer.parseInt(secondNum.getString());
                   sum = (first + second);
                   sumBox = new TextBox("Summation", "The summation is\n"+sum, 25, TextField.ANY);
                   sumBox.addCommand(exitCommand);
                   sumBox.setCommandListener(this);
                   display.setCurrent(sumBox);
    }

    only StringItem supports setFont(Font) method. if you want the Font support for TextField
    and TextBos, you should implements it !
    or write your own CustomItem
    good luck

  • How to use Synclast MIDP in netbeans

    Hi i have downloaded the Synclast MIDP UI from http://sourceforge.net/project/showfiles.php?group_id=83391 but i am having trouble finding a way to use it in my j2me project netbeans
    does anybody know how to use these UI has i want to customize a forms appearance, eg set the form to appear in full screen, add colour, change fonts etc...
    i was looking at using j2me polish but i cant get it to work with netbeans 5.5

    Bob_Unitt wrote:
    Yucca wrote:
    Well once again these commands will verify your installatiion as follows...bobunitt@****:~$ java -versionjava version "1.6.0_0"
    OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu7)
    OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)
    bobunitt@****:~$ javac -version
    javac 1.6.0_0
    Note that this was installed with Synaptic Package Manager, and should therefore be the 'correct' version for Ubuntu 9.04.
    I've now tried installing the package 'javahelp2-doc' as well, but that hasn't made any difference.
    I use ubuntu same as you.. I had issues with the JDK and JRE and found that one needed to uninstall the iced tea JDK and co. to be able to install the proper JRE and JDK The version you are using does not provide the "nimbus" look and feel which is not an issue but was for me.

  • Why same custom designed item looks different on different MIDP phones?

    Same MIDP application looks different on different phones, which is obvious. But the sizes of custom items are also looks different, which is some thing trouble some. IE the custom designed button of size say 50 X 20, looks proper on BlackBerry MIDP phone, but same button looks very small [cant even recognize] on Nokia MIDP phone. Why it is so?
    Is there any way to design items as per the phone dimensions? Regards.
    Note: I want to get standard item size, font size etc. so that I can use them directly. In this case on every device the designed items will look proper
    Edited by: nikhil_shravane on Aug 21, 2010 04:27 AM

    The look depends on mainly three things, the screen size, screen resolution and dpi. Although dpi is related to the ration of screen size and screen resolution. If the dpi is higher, the same image or item will look smaller than from a device which has a lower dpi. Like the iPhone and BB Bold both has almost identical screen resolution, however Bold has a higher dpi so the same image or a html page looks smaller on Bold than it is in iPhone.
    Regards,
    SD

  • How can I load font in real device?

    I am building mobile text SMS in my native country language using j2me wireless toolkit. But I face one problem. Without installing font in windows font directory, I did not display my country font. I used Unicode for my project. My question is:
    * How does the real device get my desire font without install it to device.
    * If I want to give fontname.ttf file with my package. Where can I load this file in midlet package/ midlet suite? Does it work on device?
    Please, help me.
    Babu

    Hi,
    U can try this
    http://developers.sun.com/techtopics/mobility/midp/articles/termemulator3/

  • Trouble porting a game from J2SE to MIDP

    Hello, I'm a J2SE programmer trying to learn how to code for MIDP 1.0 and 2.0 phones. I've gone through some examples and tutorials to learn how to create a basic game, and I've taken a simple one that I've written and modified it so that I believe it should work for MIDP 2.0. However, when I try to run it in my emulator, it bails immediately with the following error:
    java.lang.Error: Static initializer: java/lang/IllegalArgumentException: Unsupported size
         at com.sun.midp.midlet.MIDletState.createMIDlet(+60)
         at com.sun.midp.midlet.Scheduler.schedule(+52)
         at com.sun.midp.main.Main.runLocalClass(+28)
         at com.sun.midp.main.Main.main(+116)
    I haven't been able to find out from anywhere what this error means or what I can do to fix it. Any help would be greatly appreciated, thank you!

    turns out, I was passing a number for a font size somewhere, where I should have had one of the small/medium/large type parameters. Silly misleading errors

  • Problem in changing List control's font..!!

    Hi.. I'm having this problem where if I take a listbox & add 15 items to it & change the font of each item in a loop
    using the function below, it works perfect..
    //sets font for every item in List used in the application
         private void SetListBoxItemsFont(List lstBx)
              Font FONT_APPLICATION = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
              for(int i=0;i<lstBx.size();i++)
                   lstBx.setFont(i, FONT_APPLICATION);
         }     but now if I clear the list control & add 5 items(less than the earlier one)
    and call out the same function to change the font.. it throws an error..
    java.lang.ArrayIndexOutOfBoundsException
         at javax.microedition.lcdui.ChoiceGroup.insertImpl(+317)
         at javax.microedition.lcdui.ChoiceGroup.append(+25)
         at javax.microedition.lcdui.List.append(+9)
         at TimingsDialog.SetTimings(+128)
         at SelectRoutesDialog.commandAction(+189)
         at javax.microedition.lcdui.List.callKeyPressed(+80)
         at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
         at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
         at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+121)
         at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
         at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+178)
    what do you think is the problem?? please help...

    Hi Dayson, this is how far I could get --
    The top of the stack trace in NetBeans:
    java.lang.ArrayIndexOutOfBoundsException
            at javax.microedition.lcdui.ChoiceGroup.insertImpl(ChoiceGroup.java:1402)
            at javax.microedition.lcdui.ChoiceGroup.append(ChoiceGroup.java:388)
            at javax.microedition.lcdui.List.append(List.java:423)List.append    public int append(String stringPart, Image imagePart) {
            return cg.append(stringPart, imagePart);
    cg is an instance field, class of cg is ChoiceGroup.
    ChoiceGroup.append    public int append(String stringPart, Image imagePart) {
            int returnVal = -1;
            synchronized (Display.LCDUILock) {
                checkNull(stringPart, imagePart);
                returnVal = insertImpl(numOfEls, stringPart, imagePart);
            return returnVal;
        }ChoiceGroup.insertImpl    private int insertImpl(int elementNum, String stringPart,
                               Image imagePart) {
            if (numOfEls == stringEls.length) {
                String[] newStrings = new String[stringEls.length + 4];
                System.arraycopy(stringEls, 0, newStrings, 0, elementNum);
                System.arraycopy(stringEls, elementNum, newStrings,
                                 elementNum + 1, numOfEls - elementNum);
                stringEls = newStrings;
                if (imageEls != null) {
                    Image[] newImages = new Image[imageEls.length + 4];
                    Image[] newMutableImages = new Image[imageEls.length + 4];
                    System.arraycopy(imageEls, 0, newImages, 0, elementNum);
                    System.arraycopy(imageEls, elementNum, newImages,
                                     elementNum + 1, numOfEls - elementNum);
                    System.arraycopy(mutableImageEls, 0, newMutableImages,
                                     0, elementNum);
                    System.arraycopy(mutableImageEls, elementNum, newMutableImages,
                                     elementNum + 1, numOfEls - elementNum);
                    imageEls = newImages;
                    mutableImageEls = newMutableImages;
                if (fontEls != null) {
                    Font[] newFonts = new Font[fontEls.length + 4];
                    System.arraycopy(fontEls, 0, newFonts, 0, elementNum);
                    System.arraycopy(fontEls, elementNum, newFonts,
                                     elementNum + 1, numOfEls - elementNum);
            } else {
                System.arraycopy(stringEls, elementNum, stringEls, elementNum + 1,
                                 numOfEls - elementNum);
                if (imageEls != null) {
                    System.arraycopy(imageEls, elementNum, imageEls,
                                     elementNum + 1, numOfEls - elementNum);
                    System.arraycopy(mutableImageEls, elementNum, mutableImageEls, // line 1402
                                     elementNum + 1, numOfEls - elementNum);
                if (fontEls != null) {
                    System.arraycopy(fontEls, elementNum, fontEls,
                                     elementNum + 1, numOfEls - elementNum);
            if (choiceType == Choice.MULTIPLE) {
                if (selEls.length == numOfEls) {
                    boolean newSelEls[] = new boolean[numOfEls + 4];
                    System.arraycopy(selEls, 0, newSelEls, 0, elementNum);
                    System.arraycopy(selEls, elementNum, newSelEls, elementNum + 1,
                                     numOfEls - elementNum);
                    selEls = newSelEls;
                } else {
                    System.arraycopy(selEls, elementNum, selEls, elementNum + 1,
                                     numOfEls - elementNum);
                selEls[elementNum] = false;
            stringEls[elementNum] = null;
            if (imageEls != null) {
                imageEls[elementNum] = null;
                mutableImageEls[elementNum] = null;
            if (fontEls != null) {
                fontEls[elementNum] = null;
            numOfEls++;
            if (choiceType != Choice.MULTIPLE &&
                    (elementNum < selectedIndex || selectedIndex == -1)) {
                selectedIndex++;
                hilightedIndex = selectedIndex;
            } else if (elementNum < hilightedIndex || hilightedIndex == -1) {
                hilightedIndex++;
            setImpl(elementNum, stringPart, imagePart);
            return elementNum;
        }I've marked line 1402, but that line relates to the images array. However, 5 lines down, line 1407 is concerned with the fonts array, so I'm assuming the code I have is slightly different from the one compiled to the ChoiceGroup.class used by NetBeans.
    This is the declaration, with comments, for fontEls, the fonts array:    /**
         * The array containing the Font of each element (null if no setFont()
         * method was ever called). If fontEls is non-null, only the elements
         * which were set by setFont() are non-null.
        private Font[] fontEls;So this becomes apparent: fontEls is non-null after setFont() has been called. Now review the code block around line 1407:            if (fontEls != null) {
                    System.arraycopy(fontEls, elementNum, fontEls,
                                     elementNum + 1, numOfEls - elementNum);
                }BUT... nowhere in the code do I find a new array being assigned to fontEls, EXCEPT in the setFont method, and that too only once... here's List.setFont    public void setFont(int elementNum, Font font) {
             cg.setFont(elementNum, font);
        } and ChoiceGroup.setFont    public void setFont(int elementNum, Font font) {
            synchronized (Display.LCDUILock) {
                checkIndex(elementNum);
                if (fontEls == null) {
                    fontEls = new Font[numOfEls];
                fontEls[elementNum] = font;
        }With this knowledge, I reduced your code to the smallest possible that should demonstrate the bug -- and I did get the NullPointerException thrown by ChoiceGroup.insertImpl. This is the code I tested:package dayson;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.List;
    public class TestList extends List {
        final Font FONT_APPLICATION = Font.getFont (Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        public TestList () {
            super ("", List.IMPLICIT);
            append ("", null);
            setFont (0, FONT_APPLICATION);
            append ("", null);
    }I think this makes enough sense to submit a bug report to Sun. Would you like to do the honours? Do post the bug ID here, I believe there's a system of voting for bugs -- the bugs with the most votes get fixed soonest.
    db
    To other readers of this: sorry for the length of this post, but the topic merited it.

  • Custom font

    hi all,
    Being relatively new to j2me, I've encountered a bit of a road block. I'm having trouble rendering customized font to a mobile device. Specifically, a Samsung T809.
    I've created .png files and bitmap files using various applications
    and used following code to make the background transparent.
    private static Image calcBlend(Image tmpImg){
    int tmpWidth = tmpImg.getWidth();
    int tmpHeight = tmpImg.getHeight();
    int[] raw = new int[tmpWidth * tmpHeight];
    tmpImg.getRGB(raw, 0, tmpWidth, 0, 0, tmpWidth, tmpHeight);
    for(int i=0; i<raw.length; i++){
    int a = 255;//visible
    int color = (raw[i] & 0x00FFFFFF); // get the color of the pixel.
    if(0x00FFFFFF==color){
    a = 0;//transparent
    a = (a<<24); // left shift the alpha value 24 bits.
    color += a;
    raw[i] = color;
    return Image.createRGBImage(raw, tmpWidth, tmpHeight, true);
    It works well with the emulator, but when uploaded to a mobile device,
    it will display the font with white opaque background.
    Has anyone run into something like this before? any advice would be greatly appreciated...

    {color:#000080}There's nothing wrong here. Test it on other devices, some devices have bugs.
    Use{color} {color:#008000}javax.microedition.lcdui.Display.numAlphaLevels(){color}{color:#000080} to confirm that the device supports transparency. The minimum legal return value is 2, corresponding to the fully transparent & fully opaque conditions.
    Since: MIDP 2.0
    db
    To post code, use code tags -- [code]CODE[/code] is displayed as CODE{color}

  • Font.subStringWidth returns 0 inadequately

    i'm developing with MIDP 1.0 for a # Nokia 7210 (serie 40).
    the function Font.substringWidth(string, off, len) return 0 in some case when len !=0 and off is in the good range.
    how come ?

    resolved

Maybe you are looking for