Iterate over components in a HorizontalLayout

I have a HorizotnalLayout

HorizontalLayout navBar = new HorizontalLayout();
Button button1 = new Button("button1");

How can i iterate over navBar to change text of button1?

Keep the reference to button1.

public class MyView extends VerticalLayout {
	private Button button1;

	public MyView {
        HorizontalLayout navBar = new HorizontalLayout();
        button1 = new Button("button1");
	private void doSomething() {
        button1.setCaption("I've done it!");

Thanks for your answer. But my problem is a little bit different.

I hava a MainView where i add the navBar

public class TopNav extends Div {
	public final String ID_USER_BUTTON = "IdUserButton";

	private HorizontalLayout topNavigation;
	private Button homeButton;
	private Button mailButton;
	private Button userButton;
	public TopNav() {
		topNavigation = new HorizontalLayout();

		Icon iconHome = new Icon(VaadinIcon.HOME);
		homeButton = new Button();
		homeButton.addClickListener(e -> {
			homeButton.getUI().ifPresent(view -> view.navigate("HomeView"));

		mailButton = new Button("Email");
		mailButton.addClickListener(e -> {
			mailButton.getUI().ifPresent(view -> view.navigate("MailView"));

		String userName = "abc";
		userButton = new Button(userName);
		userButton.addClickListener(e -> {
			userButton.getUI().ifPresent(view -> view.navigate("UserView"));
		topNavigation.add(homeButton, mailButton, userButton);
	public void setUserButtonCaption(String caption) {
@Viewport("width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes")
@Theme(value = Lumo.class)
public class MainView extends HorizontalLayout implements RouterLayout {

	private static final long serialVersionUID = 1L;
	private TopNav topNav;

	public MainView() {
		topNav = new TopNav();

I want now to set in the HomeView the Text of my userButton with an Value i have set in the Session.

Something like

@Route(value = "HomeView", layout = MainView.class)
public class HomeView extends VerticalLayout {

	TopNav topNav;

	private static final long serialVersionUID = 1L;
	public static final String VIEW_NAME = "HomeView";

	void init() {
		topNav.setUserButtonCaption("Hallo Welt");

When i make it so in class HomeView, the Text of userButton doesn’t change?

layout.getChildren().forEach( child -> { /* do something with child */ } );