Hi I have a text field on my screen but its tiny:

<panel height="13%" width="100%" childLayout="vertical">
    <text id="label1" height="50%" font="Interface/Fonts/MinionPro.fnt" color="#f00f"
          text="Hello World!" align="center" valign="center" />
<panel height="10%" width="100%" backgroundColor="#55a5" childLayout="center">
    <control name="textfield" text="Some text"/>

the problem is I can not figure out how to change the font size on it. Please help me out here.


In jME/Nifty, each letter is basically a Quad with a Texture on it. Scaling font-textures usually looks horrible and I guess that's why Nifty doesn't provide an option for scaling (you can scale BitmapText in jME though).

Easiest way is to generate a new, bigger font. If you're using the jME SDK there's a built-in generator. Right click on a folder in the Projects Window and choose New -> Other -> GUI -> Font.

I recommend a padding of 2 for X and Y. Otherwise you might see random dots in the rendered text (these are parts of other letters that are overlapping the letter box in the texture).

Sometimes there's a huge gap between the letters. You can control that by using negative values for "letter spacing".

Nifty's Textfield-Control is a composition of panels and text elements. To use a bigger font you have to redefine its style. Grab the original nifty-textfield.xml from your nifty-style-black.jar or from here: https://github.com/nifty-gui/nifty-gui/blob/1.4/nifty-controls-style-black/src/main/resources/textfield/nifty-textfield.xml

Save it somewhere in your Assets/Interface folder and include it in your other XML like this:
(Make sure to include it after nifty-default-styles.xml)

<useStyles filename="Interface/textfield.xml" />

Now you have to adjust the style. Remove the base="base-font" attribute from the style with ID nifty-textfield#text and add font to the attributes-Tag. It should look like this:

<style id="nifty-textfield#text">
    <attributes ... font="Interface/Fonts/YourFont-24.fnt" />

You probably also want to change the size of the Textfield to match the new font. Edit the other styles in this file as you need.

The Nifty Manual explains controls and styles in more detail:

  • \$\begingroup\$ Is there a way to apply this concept for multiple resolutions? \$\endgroup\$ – serge Dec 23 '15 at 10:59
  • 1
    \$\begingroup\$ You could define multiple style sets - one for each resolution - all using the same names for the styles. Then check the resolution in java and add the appropriate style.xml with Nifty.addXml(). I think you could use the base="base-style" attribute so you only have to redefine the differences. Maybe this is useful to you: stackoverflow.com/questions/23265892/… \$\endgroup\$ – 1000ml Dec 23 '15 at 13:16

There is no way to resize fonts within a label, as pointed out in this JMonkeyEngine forum post.

You can't currenty set the text size of a Label in Nifty. This is mainly due to the use of bitmap based fonts which usually don't resize very well. You need to use different fonts for best visual appearance if you need different text sizes.

  • \$\begingroup\$ but its not a label it text input, and on label I still able to set font but not on textfield \$\endgroup\$ – serge Dec 21 '15 at 23:38
  • \$\begingroup\$ Same thing either way, though. \$\endgroup\$ – user67192 Dec 21 '15 at 23:39
  • \$\begingroup\$ but how do I set font to it since I can do it for label, the font attribute did not work \$\endgroup\$ – serge Dec 21 '15 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.