Nifty window ChildLayout() not working correctly [update]

Hi all,

I´ve tried to create a window via Java, but it seems like the childLayout method is not working correctly. :confused:

parentLayer = screenTest.findElementByName("HUD-Layer2");
windowBuilder = new WindowBuilder();
windowBuilder.id("HUD-Economy-Window" + idCountMain);
windowBuilder.height("70%");
windowBuilder.width("50%");
windowBuilder.x(width + "px");
windowBuilder.y(height + "px");
windowBuilder.childLayoutVertical();
windowBuilder.build(nifty, screenTest, parentLayer);

Every new “item”, which I try to put into the window, will be created at the bottom of the window and not at the top. valign is not fixing this problem.

If I put the same “items” into a panel, it´s working without problems.
Instead of using the window control I could use the draggable + droppable controller, but I would prefer to stay “native” :slight_smile:

Thanks in advance. :slight_smile:

Update: Another problem has appeared regarding the window. I cannot disable the close button via method (I want to implement my own close button because the default one has no way to “activate” an event based on the close action). I also get an error message if I push the close button of the window (regardless if the closeable method is true or false): “wrong number of arguments”.

You need to add elements in the content panel of the window not to the window element itself. You can get the content panel with this method:
nElement.getControl(WindowControl.class).getContent()

Update: Another problem has appeared regarding the window. I cannot disable the close button via method (I want to implement my own close button because the default one has no way to “activate” an event based on the close action). I also get an error message if I push the close button of the window (regardless if the closeable method is true or false): “wrong number of arguments”.

Have you tried this method from the builder? : public void closeable(final boolean closeable)

1 Like

Thanks for your reply. :slight_smile:

I´ve tried the way using “nElement.getControl(WindowControl.class).getContent()”, but everything is centered now. I also have no option to set the childLayout of the content panel.

Yes, I´ve tried to use the closeable method, but it´s not working. :confused: I also get the mentioned error message if I close the window.

Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker callMethod
Warnung: RuntimeException: java.lang.IllegalArgumentException: wrong number of arguments
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: sun.reflect.NativeMethodAccessorImpl invoke0 (NativeMethodAccessorImpl.java:-2)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: sun.reflect.NativeMethodAccessorImpl invoke (NativeMethodAccessorImpl.java:57)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: sun.reflect.DelegatingMethodAccessorImpl invoke (DelegatingMethodAccessorImpl.java:43)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: java.lang.reflect.Method invoke (Method.java:606)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.NiftyMethodInvoker callMethod (NiftyMethodInvoker.java:145)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.NiftyMethodInvoker performInvoke (NiftyMethodInvoker.java:104)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty$DelayedMethodInvoke perform (Nifty.java:1174)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty invokeMethods (Nifty.java:1152)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty handleDynamicElements (Nifty.java:354)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty access$1700 (Nifty.java:77)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processEvent (Nifty.java:1374)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty$NiftyInputConsumerImpl processMouseEvent (Nifty.java:1329)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.niftygui.InputSystemJme handleMouseEvent (InputSystemJme.java:124)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.niftygui.InputSystemJme onMouseButtonEventQueued (InputSystemJme.java:232)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.niftygui.InputSystemJme forwardEvents (InputSystemJme.java:296)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: de.lessvoid.nifty.Nifty update (Nifty.java:288)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.niftygui.InputSystemJme endInput (InputSystemJme.java:113)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.input.InputManager processQueue (InputManager.java:819)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.input.InputManager update (InputManager.java:883)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.app.Application update (Application.java:604)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.app.SimpleApplication update (SimpleApplication.java:231)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.system.lwjgl.LwjglAbstractDisplay runLoop (LwjglAbstractDisplay.java:151)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.system.lwjgl.LwjglDisplay runLoop (LwjglDisplay.java:185)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: com.jme3.system.lwjgl.LwjglAbstractDisplay run (LwjglAbstractDisplay.java:228)
Okt 29, 2014 10:09:58 PM de.lessvoid.nifty.NiftyMethodInvoker logException
Warnung: java.lang.Thread run (Thread.java:744)

parentLayer = screenTest.findElementByName("HUD-Layer2");
windowBuilder = new WindowBuilder();
windowBuilder.closeable(false);
windowBuilder.id("HUD-Economy-Main" + idCountMain);
windowBuilder.height("70%");
windowBuilder.width("50%");
windowBuilder.x(positionX + "px");
windowBuilder.y(positionY + "px");
windowBuilder.childLayoutVertical();
windowBuilder.style("nifty-window");
windowBuilder.build(nifty, screenTest, parentLayer);
idCountMain++;
windowContentPanel = screenTest.findElementByName("HUD-Economy-Main" + (idCountMain-1));
windowContentID = windowContentPanel.getControl(WindowControl.class).getContent().getId();
        
parentPanel = screenTest.findElementByName(windowContentID);
createPanel1 = new PanelCreator();
createPanel1.setId("HUD-Economy-Content" + idCountContent);
createPanel1.setHeight("20%");
createPanel1.setWidth("100%");
createPanel1.setBackgroundColor("#f00f");
createPanel1.setChildLayout("center");
createPanel1.setStyle("nifty-panel-simple");
createPanel1.create(nifty, screenTest, parentPanel);
idCountContent++;

Update: I found a solution for the childLayout. I had to add another panel. On void´s page there´s an entry about this:

“Please Note: By default windows use a CenterLayout for the content. So make sure that you add a panel with another childLayout if you plan to have several elements/controls in your window.”

Update 2: I found a way to solve the other problem, too. I use the DraggableBuilder (https://github.com/void256/nifty-gui/wiki/Drag’n’Drop) including a close “button”.