NIFTY GUI: changing the label of a button

I have the following code that creates a menu with 3 buttons:

[java]private ScreenBuilder createScreen()
{
return new ScreenBuilder(“player”) {{
controller(HudController.this);
layer(new LayerBuilder(“background”) {{

            childLayoutCenter();

            panel(new PanelBuilder("panel_hud") {{
                childLayoutHorizontal();
            }});

            layer(new LayerBuilder("left_side_layer") {{

                childLayoutHorizontal();
                alignLeft();
                valignTop();

                panel(new PanelBuilder("panel_modifier_buttons") {{

                    // sets the menu to horizontal
                    childLayoutHorizontal();

                    // align it to left top
                    alignLeft();
                    valignTop();

                    // width of the buttons
                    width("20%");

                    control(constructButton("ShowEnergy", "Energy Level"));
                    control(constructButton("ShowPower", "Power Level"));
                    control(constructButton("ShowHelp", "Help"));

                }});
            }});

            layer(new LayerBuilder("dialog_panel_layer") {{
                childLayoutCenter();
                layer(new LayerBuilder("dialog_selection_layer") {{
                    childLayoutAbsolute();
                }});
            }});
        }});
    }};
}

private ButtonBuilder constructButton(String id, String label)
{
return new ButtonBuilder(id, label) {{
width(“100%”);
alignCenter();
valignCenter();
visibleToMouse(true);
this.focusable(false);
}};
}

[/java]

Is there any way I could change the label of the button after the menu has already been constructed? There is a method set() to change that. But the question is how can I access that. I tried playing around with screen.findElement… but it got a little confusing. Can anyone guide me on this one?

A button is essentially a panel and a text element. So you need to do something like this (I think)

[java]buttonElement.getRenderer(TextRenderer.class).setText(“NewText”);[/java]

2 Likes

actually the way it turned out to be was but finding the nifty element and setText() the trick for me was how to find the nifty element but it was shown in the documentation. Should have looked more …
thanks!!