[SOLVED] Nifty getting null renderer from valid element

Hi, I am trying to make an input dialog on nifty, its an popup.
In the creation event I am doing this :

    Element thispopup = nifty.createPopupWithId("popupInput", "popupInput");
    Element textfield = thispopup.findElementByName("GTextfield");
    nifty.showPopup(screen, "popupInput", null);

thispopup is not null , textfield is not null and its an textfield control , but when I try to take the textenderer, it gets null …

What am I doing wrong ? Cant I change an popup input text ?

Funy thing :


== ImageRenderer !!!

How come ? There is not even any image in this popup !

Following the popup code :

<popup id="popupInput" childLayout="center" backgroundColor="#000a">
      <onStartScreen name="fade" startColor="#0000" endColor="#000a" length="250" />
      <onStartScreen name="playSound" sound="robotArmLow" startDelay="250" />
      <onEndScreen name="fade" startColor="#000a" endColor="#0000" length="250" startDelay="250" />
    <panel style="nifty-panel-bright" childLayout="center" padding="18px,28px,40px,16px" width="35%" height="20%" align="center" valign="center">
        <onStartScreen name="fade" start="#0" end="#f" length="150" startDelay="1000"/>
        <onStartScreen name="imageSize" timeType="exp" factor="3.5" startSize="1.5" endSize="1.0" inherit="true" length="150" startDelay="1000"/>
        <onEndScreen name="fade" start="#f" end="#0" length="150" startDelay="0"/>
        <onEndScreen name="imageSize" timeType="exp" factor="3.5" startSize="1.0" endSize="1.5" inherit="true" length="150" startDelay="0"/>
      <panel childLayout="vertical" align="center" width="100%" height="100%" valign="center">
          <onStartScreen name="alphaHide" length="500" inherit="true" />
          <onEndScreen name="fade" length="10" start="#f" end="#0" inherit="true" />
        <panel childLayout="vertical" height="80%" width="100%">
          <text text="Enter the Profile Name" style="base-font" height="50%" align="center" valign="center" color="#000f"/>
          <control name="textfield" id="GTextfield" height="50%" width="100%" y="66" x="28"/>
        <panel childLayout="horizontal" align="center" height="10%"/>
        <panel childLayout="horizontal" align="center" height="10%">
          <panel childLayout="center" width="50%">
            <control id="yesButton" name="button" label="Yes" width="130px" align="center">
              <interact onClick="popupExit(yes)" />
          <panel childLayout="center" width="50%">
            <control id="noButton" name="button" label="No" width="130px" align="center">
              <interact onClick="popupExit(no)" />

Is the textField not just a textfield? It’s not a label, I don’t think it has a TextRenderer. Can’t you just grab it as a TextField.

import de.lessvoid.nifty.controls.TextField;

final TextField textField = thispopup.findNiftyControl("GTextfield", TextField.class);

Its working !
I thought the other syntax should work… Its just an textfield after all.
Well, I just learn another way to do it, thanks friend !

Avoid using Elements if you want access to a specific control and it’s functionalities, even though they are elements or wrappers of multiple elements it’s not straight forward using them as elements, that’s why they are controls :smiley:

1 Like