Set ComponentContainer in navigator

I uss vaadin 8 with navigator
I create a navigator with:

Csslayout firstContainer = new CssLayout();
Navigator navigator = new Navigator(this, firstContainer);
navigator.addView(MAINVIEW, new FirstView());

MainView is shown in container.

Later in the same progam i want to change container to newContainer like:

CssLayout secondContainer = new CssLayout();
navigator.setComponentContainer(secondContainer);
navigator.addView(SECONDVIEW, new SecondView())
=> or something like _this.

I want that SecondView is shown in newContainer.
How can i change it?

Should the main view still be shown in the first css layout? What is the intention of having two CSS Layouts?

I have edited my Posting for better understanding:
the firstView should be shown in firstContainer
the secondView should be shown in secondContainer

I have View01 with a HorizontalMenue and firstContainer for the content.
When i choose a Menue-Point in this Horizontal-Menue

  • i want to show View02 in firstContainer
  • View02 has a sidebar and secondContainer for the his content

I would recommend you to use the ViewDisplay interface instead. It gives you a solid control of how the views are displayed as they are shown. Just implement the method showView(View) where you can add the view into your matching css layout

@Override
public void showView(View view) {
    clearLayouts(); // removes old view instances. 
    if(view instanceof MainView) {
      	firstCssLayout.addComponent(view.getViewComponent());
        setContent(firstCssLayout);
    } else if(view instanceof SecondView) {
     	secondCssLayout.addComponent(view.getViewComponent());
        setContent(secondCssLayout);
    }
}

All you have to do then is to register the UI as the view display in your Navigator instance in the UI’s init method.

public class MyUI extends UI implements ViewDisplay {

@OVerride
protected void init (VaadinRequest request) {
   //...
   Navigator navigator = new Navigator(this, (ViewDisplay) this);
   //...;
}
// ...

(Just small examples of course to represent the handling of view display).

thanks