Issue with TextFieldBuilder

Hi,



First so glad we moved to 1.3 :slight_smile:



I am Having issue with TextFieldBuilder. It semply not showing anything no matter I put in width

the only thing I see is the cursor



The only way see something is to add a default value. and in that case only the default value shows, ie

textfield width is the width of the default string I put



Sample code to reproduce in JME is

[java]Screen screen = new ScreenBuilder("start") {{

layer(new LayerBuilder("dialogLayer") {{

childLayoutCenter();

panel(new PanelBuilder("dialog-parent"){{

height("200px");

width("200px");

align(Align.Center);

valign(VAlign.Center);

childLayoutCenter();

backgroundColor(Color.WHITE);

control(new TextFieldBuilder("chatInput"){{

childLayoutHorizontal();

width("100px");

}});

}});

}});

}}.build(nifty);

nifty.addScreen("start", screen);

nifty.gotoScreen("start");[/java]



that will show only a white panel with a cursor inside no text field



anybody had/is having same issue?



in advance thx

Pit

Well, the drawback of given you early access to Nifty 1.3 is that you’ll find out about some things the hard way and not while reading a well written documentation in the wiki :slight_smile:



You’ll need to load the styles and the controls before you create the screen. You’ll need to do something like:



[xml]nifty.loadStyleFile(“nifty-default-styles.xml”);

nifty.loadControlFile(“nifty-default-controls.xml”);[/xml]

I did that



here is the code just before



[java]inputManager.clearMappings();

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);

nifty = niftyDisplay.getNifty();

nifty.loadStyleFile("nifty-default-styles.xml");

nifty.loadControlFile("nifty-default-controls.xml");

// attach the nifty display to the gui view port as a processor

guiViewPort.addProcessor(niftyDisplay);[/java]

so here is the complete code



[java]public class TestTextField extends SimpleApplication implements AnalogListener,ActionListener{



public static MessageHandler messageHandler = new MessageHandler(false);





private Nifty nifty;

public static TestTextField app;





public static void main(String[] args) {

app = new TestTextField();

app.setShowSettings(false);

AppSettings settings = new AppSettings(true);

settings.put("Width", 1280);

settings.put("Height", 720);

settings.put("Title", "SpaceLife");

settings.put("BitsPerPixel", 24);

settings.put("Frequency", 60);

settings.put("DepthBits", 24);

app.setSettings(settings);

app.start();

}









@Override

public void simpleInitApp() {



inputManager.clearMappings();

NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);

nifty = niftyDisplay.getNifty();

nifty.loadStyleFile("nifty-default-styles.xml");

nifty.loadControlFile("nifty-default-controls.xml");

// attach the nifty display to the gui view port as a processor

guiViewPort.addProcessor(niftyDisplay);



Screen screen = new ScreenBuilder("start") {{

layer(new LayerBuilder("dialogLayer") {{

childLayoutCenter();

panel(new PanelBuilder("dialog-parent"){{

height("200px");

width("200px");

align(Align.Center);

valign(VAlign.Center);

childLayoutCenter();

backgroundColor(Color.WHITE);

control(new TextFieldBuilder("chatInput"){{

childLayoutHorizontal();

width("100px");

}});

}});

}});

}}.build(nifty);

nifty.addScreen("start", screen);

nifty.gotoScreen("start");

flyCam.setDragToRotate(true);





}[/java]

remove the “childLayoutHorizontal();” call within the “new TextFieldBuilder(“chatInput”){{” and it will work.



This specific “problem” is a drawback of the way that builder mechanism works. You can see the blog post here for details http://nifty-gui.lessvoid.com/archives/179



Especially see this note in the blog post:



—

Please Note:



As we’re creating annonymous inner classes each time we add a new xxxBuilder() {{ }} method and we’re nesting them it’s possible to access methods from the previous annonymous class and that could be confusing because we could misconfigure the parent element. So it’s probably best to only use methods from the current Builder class.

—



It’s odd. I know and I don’t like this because it’s not obvious that you’re changing the PanelBuilder and not the TextFieldBuilder in your case (it’s not necessary to set childLayoutHorizontal() for the TextFIeldBuilder btw) but we’ve not yet found a nice solution for this yet :confused: So for the moment you just need to be careful.

Wonderfull!!! works like a charm

thx a lot. :slight_smile: