Button font XML tag

It seems if I use font=“path/to/font.fnt” in a XML button control definition it’s not working. The font used is the default one (probably the one used in nifty’s button definition class).



Is it something I’m doing wrong?



Also, a couple of things.



If I use this:

[java]screen.findNiftyControl(“mnuLoadGame”, ButtonControl.class).getFont().toString()[/java]



I get: Font: com.jme3.niftygui.RenderFontJme@571a4bd4



Would it be possible to get the font name instead of the reference when using toString()?



Lastly, I checked to programatically change the font by using setFont(…) but that method asks for RenderFont. Honestly, I have no idea how to generate a RenderFont. I haven’t looked it up but I’m wondering how I could do so.



Last second: getFont() returns RenderFontJme, setFont() demands RenderFont? scratch head

Have you tried looking at the stylesheet code? I find that changing stylesheets changes the fonts everywhere, including on the buttons.

Thanks!



I’ll take a look at that!

RenderFontJme is an implementation of RenderFont (an interface)

Use the constructor of RenderFontJme to create new instances of it

Thanks Momoko_Fan, I’ll try that.

@ractoc said: Have you tried looking at the stylesheet code? I find that changing stylesheets changes the fonts everywhere, including on the buttons.

I changed the style sheets and is able to align the text to left successfully.
However, with fonts it does not work either.

[java]<!-- +++++++++++++++++++++++++++++++++++++ –>
<!-- style for the button text –>
<!-- +++++++++++++++++++++++++++++++++++++ –>
<style id=“nifty-button#text” base=“button-font”>
<attributes align=“center” font=“Interface/Fonts/LucidaSans.fnt” valign=“center” textHAlign=“center” textVAlign=“center” visibleToMouse=“false”/>
<effect>
<onEnabled name=“textColorAnimated” startColor=“#8886” endColor=“#eeef” post=“false” length=“150” />
<onDisabled name=“textColorAnimated” startColor=“#eeef” endColor=“#8886” post=“false” length=“150” />
</effect>
</style>
</nifty-styles>[/java]

@madjack
Have you been able to change the size of text in buttons? I think these are labels so we can’t change the size of text in there. Kindly let me know if anyone has been able to change size of text in buttons in nifty?

You do realize this topic is over 3 years old? There’s been lots of changes since then. The biggest, most important one here, is that don’t use Nifty anymore. Haven’t in over a year, if not more.

Can’t really help.

@madjack said: You do realize this topic is over 3 years old? There's been lots of changes since then. The biggest, most important one here, is that don't use Nifty anymore. Haven't in over a year, if not more.

Can’t really help.

Sorry, thats the only topic I found on this. Anyways the post did help me. It put me in the right direction so I figured it out.

For other people searching for this, Instead of nifty-default-styles.xml change “nifty-default-controls.xml” to point to a custom “nifty-button.xml”

[java]<?xml version=“1.0” encoding=“UTF-8”?>
<nifty-controls>
<controlDefinition style=“nifty-button” name=“button” controller=“de.lessvoid.nifty.controls.button.ButtonControl” inputMapping=“de.lessvoid.nifty.input.mapping.MenuInputMapping”>
<panel style=“#panel” focusable=“true”>
<text id=“#text” style=“#text” font=“Interface/Fonts/TimesNewRoman.fnt” text=“$label”/>
</panel>
</controlDefinition>
</nifty-controls>
[/java]