Nifty - Loading Default Controls and Styles

Hi there! I’m learning Nifty GUI, and trying to implement my own, simple GUI. What’s stumping me is these couple of lines:

<useStyles filename = "nifty-default-styles.xml" />
<useControls filename = "nifty-default-controls.xml" />

I have looked online and found that they are located in the jme3-libraries jar files. I would like to load them in my XML files, if possible. If I try that code in my XML file, however, I get an asset not found exception. Without those lines, the XML loads fine if I remove the control.

Is the only way to load them is by copy-pasting them in my Interface folder? It seems rather archaic, so I figured there might be another way I’m not seeing.

Thanks!

Full XML File:

<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.sourceforge.net/nifty-1.3.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://niftygui.sourceforge.net/nifty-1.3.xsd http://nifty-gui.sourceforge.net/nifty-1.3.xsd">

    <!-- load styles -->
    <useStyles filename = "nifty-default-styles.xml" />
    <useControls filename = "nifty-default-controls.xml" />

    <!-- start screen -->
    <screen id = "start" controller = "editor.Editor">
        <layer id = "overlay" backgroundColor = "#00000055" childLayout = "center">
        </layer>
        <layer id = "background" childLayout = "center">
            <panel backgroundColor = "#ffffffff" width = "75%" height = "90%" childLayout = "vertical">
                <text font="aurulent-sans-16.fnt" color = "#000000ff" text = "SETTINGS" align = "center" textLineHeight = "32px" />
                <text font="aurulent-sans-16.fnt" color = "#000000ff" text = "TILE TYPE" align = "center" textLineHeight = "32px" />
                <control id="type" name="type" displayItems = "3">
                </control>
            </panel>
        </layer>
    </screen>
</nifty>

Exception Stack Trace:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: com.jme3.asset.AssetNotFoundException: Interface/Editor.xml
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:577)
	at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:480)
	at editor.Editor.<init>(Editor.java:23)
	at main.Main.simpleInitApp(Main.java:29)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
	at java.lang.Thread.run(Thread.java:744)
Caused by: com.jme3.asset.AssetNotFoundException: Interface/Editor.xml
	at com.jme3.niftygui.NiftyJmeDisplay$ResourceLocationJme.getResourceAsStream(NiftyJmeDisplay.java:82)
	at     de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader.getResourceAsStream(NiftyResourceLoader.java:65)
	at de.lessvoid.nifty.Nifty.getResourceAsStream(Nifty.java:1583)
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:569)
    ... 7 more

Have you tried changing the name of the file and cleaning and building?

And likely yes it would probably be easiest just to put it inside that directory and edit it there.

That’s right - assets/Interface/Editor.xml

As I said, if I remove the tag, it still fails to work. The problem, I believe, is that the nifty-default-styles.xml and nifty-default-controls.xml are not found - obviously because they are not in the same directory.

I considered copy-pasting those two files into the Interface directory, but they themselves require more files.

I’m missing your intent.

“These files are in the jar files.” “I fail to find them.”

Indicates that you have failed to include the jars files as dependencies? But I feel like there is a missing “but” in there as to why exactly you don’t want to include the jar files.

Sorry, I think I didn’t do a good job of explaining. I have located the .jar files (in the Libraries folder). Simply put, I don’t know how to include the style files in those libraries from my nifty XML file.

Include the jars as a dependency.

Look in the jars for the path to the files.

Use those paths in your XML file.

Which of those is giving you issues? Do you understand that the asset manager is just loading things from the classpath?

I think that is what I’m doing wrong. Below is my libraries folder in Tree view. If I understood you well, the classpath for the libraries is this: C:/Program Files/jmonkeyplatform/jmonkeyplatform/libs/.

I have been trying to modify this code, but I can’t seem to get it to work:

<useStyles filename = "Libraries/jme3-libraries - nifty-default-controls.jar/nifty-default-styles.xml" />
<useControls filename = "Libraries/jme3-libraries - nifty-style-black.jar/nifty-default-controls.xml" />

First time working with libraries in this way - to be honest, I thought that everything was relative to the Interface folder.

Bottom line is - I’m confused as to what the path should be relative to.

Thanks for your help so far!

No… they are loaded relative to the classpath. Just like classes. Just like assets. Since the file is in the root of the jar, there is no path.

Libraries/jme3-libraries - nifty-default-controls.jar/nifty-default-styles.xml

becomes:
nifty-default-styles.xml

Um that’s what I did in the original post, which failed.

Just so you know, I created a Simple Application and built atop of that. From above, this didn’t work:

<useStyles filename = "nifty-default-styles.xml" />
<useControls filename = "nifty-default-controls.xml" />

It gave me the asset not found exception.

And the jar with the default styles was actually part of your dependencies at that point?

I mean, beyond this I can’t really help. There is no magic to JME’s asset loader. If it says “foo” was not found then it means that “foo” is not on the classpath. AssetNotFoundException is pretty easy to debug like that.

Yes, it was. Aren’t dependencies set automatically with the Simple Application template? Not even copy-pasting a control example from the manual works for some reason.

What makes this particularly difficult to debug is that the exception looks like this:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.RuntimeException: com.jme3.asset.AssetNotFoundException: Interface/Editor.xml
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:577)
	at de.lessvoid.nifty.Nifty.fromXml(Nifty.java:480)
	at editor.Editor.<init>(Editor.java:23)
	at main.Main.simpleInitApp(Main.java:29)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
	at java.lang.Thread.run(Thread.java:744)
Caused by: com.jme3.asset.AssetNotFoundException: Interface/Editor.xml
	at com.jme3.niftygui.NiftyJmeDisplay$ResourceLocationJme.getResourceAsStream(NiftyJmeDisplay.java:82)
	at de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader.getResourceAsStream(NiftyResourceLoader.java:65)
	at de.lessvoid.nifty.Nifty.getResourceAsStream(Nifty.java:1583)
	at de.lessvoid.nifty.Nifty.loadFromFile(Nifty.java:569)
	... 7 more

This is the missing file. Find the jar with that file and add it. Or if it’s your file then make sure it’s in the right directory.

Yes, for the things that almost all apps will need. Nifty users are a shrinking minority.

Edit: in case it wasn’t clear, nifty is not a standard dependency. You have to add it.

I think that’s the problem, the thing I haven’t done. The Editor.xml file is being found, because it is loaded correctly once I remove the useStyles and useControls lines. Could you please tell me how to do that if it’s not much of a bother? I have previously downloaded the Nifty 1.4.2 zip and jar files.

Someone else will have to provide nifty support. I dropped nifty like a bad habit 6+ years ago and would rather gouge out my eyes with rusty forks than deal with it again.

Thanks all the same for your help :slight_smile:

No idea what happened - recreated the project, and now it’s working… Thanks, and sorry for wasting your time, especially you @pspeed