[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);
    textfield.getRenderer(TextRenderer.class).setText("teste");

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 :

textfield.getRenderer(ElementRenderer.class)

== ImageRenderer !!!

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

Following the popup code :

<popup id="popupInput" childLayout="center" backgroundColor="#000a">
    <effect>
      <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" />
    </effect>
    <panel style="nifty-panel-bright" childLayout="center" padding="18px,28px,40px,16px" width="35%" height="20%" align="center" valign="center">
      <effect>
        <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"/>
      </effect>
      <panel childLayout="vertical" align="center" width="100%" height="100%" valign="center">
        <effect>
          <onStartScreen name="alphaHide" length="500" inherit="true" />
          <onEndScreen name="fade" length="10" start="#f" end="#0" inherit="true" />
        </effect>
        <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>
        <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)" />
            </control>
          </panel>
          <panel childLayout="center" width="50%">
            <control id="noButton" name="button" label="No" width="130px" align="center">
              <interact onClick="popupExit(no)" />
            </control>
          </panel>
        </panel>
      </panel>
    </panel>
  </popup>

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);
textField.setText("teste");

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