Hebrew text not rendering

i have generated a .fnt file with hebrew chars, i load it but when i try to pass the text to this function:

    public static void showDialogue(String message, Application app, Node guiNode) {
    AssetManager assetManager = app.getAssetManager();

    // ✅ Register TrueTypeFont loader (only needed once)
    BitmapFont boldFont =  assetManager.loadFont("fonts/bold.fnt");
    BitmapFont regularFont = assetManager.loadFont("fonts/regular.fnt");

    int width = app.getContext().getSettings().getWidth();


    // ✅ Create the dialog panel (background)
    Container dialog = new Container();
    dialog.setPreferredSize(new Vector3f(width, 100, 0));
    dialog.setBackground(new QuadBackgroundComponent(AppColors.parchment));

    // ✅ Label 1 (Main message)
    Label label1 = new Label(message);
    label1.setFont(boldFont); // Use Hebrew-compatible font
    label1.setColor(ColorRGBA.Black);
    label1.setFontSize(24);
    label1.setColor(ColorRGBA.White);
    label1.setTextHAlignment(HAlignment.Center);

    // ✅ Label 2 (Secondary text)
    Label label2 = new Label("Second Text");
    label2.setFont(regularFont);
    label2.setFontSize(18);
    label2.setColor(ColorRGBA.White);
    label2.setTextHAlignment(HAlignment.Center);

    // ✅ Label 2 (Secondary text)
    Label label3 = new Label("Second Text");
    label3.setFont(regularFont);
    label3.setFontSize(14);
    label3.setColor(ColorRGBA.White);
    label3.setTextHAlignment(HAlignment.Center);


    // ✅ Add labels to the dialog
    dialog.addChild(label1);
    dialog.addChild(label2);
    dialog.addChild(label3);

    // ✅ Position the dialog at the center of the screen
    dialog.setLocalTranslation(0, 100, 0); // Adjust as needed

    // ✅ Attach dialog to GUI node
    guiNode.attachChild(dialog);
}

it renders empty space, in english it work, screenshot:

1 Like

Hello and welcome to the community?

Forgive me for asking. but is your default Java Locale he_IL or a Hebrew equivalent? I had issues with locales before

The locale might be a good tip. It would affect how the text is load but not how JME deals with it.

My first question then would be if you are sure that the string really contains the characters that you think it does. We don’t see how that message string was filled so it’s hard to say.

If the unicode values are correct and the font is correct then the text should display. There isn’t much magic going on beyond that. So either the font is bad or the unicode values in the string are bad.

4 Likes

that is how i use it
DialogManager.showDialogue("שלום", this, guiNode);
i deed noticed that it works when i use escape seqence, and when i try to print the chars of this string as unicode, i get some wired 007d after it

also it might be relevant that if i try:
char f = 'ף'
it not working and throwing the following exception:

error: unclosed character literal
        char f = 'ף';
                 ^

by the way if i:

        DialogManager.showDialogue( "\u05E3", this, guiNode);

then:

Something between your editor, your Java, and your OS is getting confused about character encoding.

A character looks ok in your editor and it seems to interpret it for display… but when Java tries to compile it, it is not in the encoding expected. I think .java files are supposed to be UTF-8 by default. If your editor is using “platform encoding” then you may want to switch it.

Either way, it’s a problem with the contents of your string.

I used chatgpt to try to solve this problem, so i switched to utf-8 countless times

Cool. So your problem is fixed?

Else, I’m not sure what “switched” means in this case so I cannot comment further.

The contents of your Java string were incorrect. You’d have the same issue displaying them in a Swing UI. I’m not sure how we can help further because there is too much “specific to your setup” that we don’t know and is also 100% of the issue.

Edit: let me try to put it another way that may make it easier to spot the problem.

You type a Hebrew character into your editor. The editor displays it fine.
You save the file. You load the file again. The editor still displays it fine.
This makes sense because the editor is saving the file with the same encoding that it is reading it.

However, this file is NOT saved in UTF-8. So javac tries to read the .java file as UTF-8 and sees strange non-UTF nonsense where the Hebrew character should be. When it’s a ‘char’ literal… it tells you exactly this. When it’s in a String, it does its best to interpret it and ends up with garbage.

Your String has garbage in it. You try to display the garbage. And it looks like garbage.

This is why when you specifically escape the UTF characters it works.

Switched as changed to utf-8 in intellji

By the way it still not eorks

Yeah, but the problem is not in JME, it’s on your system… so it’s difficult for us to help further.

If you can get your .java files to be in UTF-8 then I think you will be fine. (Or read your strings from a file that is in UTF-8.)

Perhaps using localization files can help in this instance since we can put all the strings in a .properties file and let it handle that. It gives room to change locales and languages.

…and somehow make sure to edit it in UTF-8.

I suspect the original problem will crop up but you never know.

If you do figure out how to edit the localization files and have them retain the correct character encoding then you can also try editing your .java files that way, too.

Edit: though maybe one has more control over reading localization files? (I don’t remember.)