eby
eby

Reputation: 191

How to add widgets to scene2d.ui Dialog (TextField etc.)?

When I create a Dialog in the way shown in the code snippet below, how can I add additional widgets (like a TextField)?

btnTest.addListener(new ChangeListener()
{
  public void changed(ChangeEvent event, Actor actor)
  {
    new Dialog("Test Dialog", globals.skin, "dialog")
    {
      protected void result (Object object)
      {
        if (object.equals(true))
        {
          if (txtID.getText() != "")
          {
             globals.appState = AppState.INTRO;
          }
        }
      }
    }.text("Enter ID")
     .button("Cancel", false)
     .button("OK", true)
     .show(stage);
  }
});

Upvotes: 1

Views: 309

Answers (1)

Ferdz
Ferdz

Reputation: 1192

Try adding a default constructor like this:

btnTest.addListener(new ChangeListener()
{
  public void changed(ChangeEvent event, Actor actor)
  {
    new Dialog("Test Dialog", globals.skin, "dialog")
    {

    {
       //Things like this.getButtonTable().add(Actor);
    }

      protected void result (Object object)
      {
        if (object.equals(true))
        {
          if (txtID.getText() != "")
          {
             globals.appState = AppState.INTRO;
          }
        }
      }
    }.text("Enter ID")
     .button("Cancel", false)
     .button("OK", true)
     .show(stage);
  }
});

Upvotes: 2

Related Questions