Nifty textfield input handling

Hi all,
I’m really newby of Nifty API, I’m trying to use a textfield to interact with my custom screencontroller:
to be clear I’m not able to input text in it.

I’m using a xml file to render the inteface, and is similar to this (i call it screen.xml)

<nifty>
	<screen id=... controller="my.CustomController">
		<layer id=... >
			<panel id=...>
				<control name="textfield" maxLength="20"></control>
			</panel>
		</layer>
	</screen>
</nifty>

when i start the app the rendering works fine but I cannot insert text typing the keyboard.
I think I’ve missed some configuration, but which? Someone can help me understand?

Um, can you show the code from you CustomController? And also maybe a screenshot what is rendered just to help understand this further. There is not enough information…

Hi tonihele,
i found a solution, there was a strange behavior: it was enough to replace the default nifty controls library to make this problem disappear. I replaced this library from default location in JMonkeyEngine SDK with the same version from maven central.

1 Like

I have the same problem. The interface reacts to the movement and clicking of the mouse, but ignores the input in the text fields. Whether the program is looking for a click handler, instead of typing, or I don’t know what.

Interface/screen.xml
<?xml version="1.0" encoding="UTF-8"?>
<nifty xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd 
https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
    <useStyles filename="nifty-default-styles.xml"/>
    <useControls filename="nifty-default-controls.xml"/>
    <screen id="start" controller="mygame.LoginScreen">
        <layer id="background" childLayout="center">
            <image filename="Interface/start-background.jpg"></image>
        </layer>
        <layer id="foreground" childLayout="center">
            <panel id="panel" height="25%" width="75%" align="center" childLayout="horizontal">
                <panel id="panel_left" height="100%" width="25%" align="left" childLayout="vertical">
                    <text text="E-mail:" font="Interface/Fonts/Default.fnt"/>
                    <text text="Password:" font="Interface/Fonts/Default.fnt"/>
                </panel>
                <panel id="panel_center" height="100%" width="50%" align="center" childLayout="vertical">
                    <control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
                    <control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>
                </panel>
                <panel id="panel_right" height="100%" width="25%" align="right" childLayout="vertical">
                    
                </panel>
            </panel>
        </layer>
    </screen>
    <screen id="hud" controller="de.lessvoid.nifty.screen.DefaultScreenController">
        
    </screen>
</nifty>
src/mygame/Main.java
package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.renderer.RenderManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        Main app = new Main();
        app.start();
    }
    public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    public Nifty nifty = null;
    @Override
    public void simpleInitApp() {
        NiftyJmeDisplay niftyDisplay = NiftyJmeDisplay.newNiftyJmeDisplay(assetManager, inputManager, audioRenderer, guiViewPort);
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("Interface/screen.xml", "start");
        guiViewPort.addProcessor(niftyDisplay);
        inputManager.beginInput();
        flyCam.setDragToRotate(true);
    }

    @Override
    public void simpleUpdate(float tpf) {
        //TODO: add update code
        nifty.update();
        inputManager.update(tpf);
    }
}
src/mygame/LoginScreen.java
package mygame;

import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;

public class LoginScreen extends BaseAppState implements ScreenController {

    @Override
    protected void initialize(Application app) {
        
    }
     
    @Override
    protected void cleanup(Application app) {
        
    }
    
    @Override
    protected void onEnable() {
       
    }
    
    @Override
    protected void onDisable() {
       
    }
    @Override
    public void update(float tpf) {
        
    }

    @Override
    public void bind(Nifty nifty, Screen screen) {
       
    }

    @Override
    public void onStartScreen() {
        
    }

    @Override
    public void onEndScreen() {
        
    }
}

The error was in XML. Interactive interface elements without an id remain static. Need not so:

<control name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>

Well right:

<control id="mail" name="textfield" maxLength="50" font="Interface/Fonts/Default.fnt"/>
<control id="password" name="textfield" maxLength="100" passwordChar="*" font="Interface/Fonts/Default.fnt"/>

Then the fields are activated.