Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Add an one layout few times.

Daniel Bojarski
6 years ago Oct 24, 2015 3:48pm
Max Schuster
6 years ago Oct 24, 2015 7:46pm

Hi Daniel,

the CustomLayout can only add one Component per slot. So if you want to add more than one Component to the slot, you'll need another VerticalLayout that holds your vl5 layouts:

CustomLayout CL = new CustomLayout([...]);
VerticalLayout rightMenu = new VerticalLayout();
rightMenu.setWidth("100%");
CL.addComponent(rightMenu , "right_menu");

And than add your vl5 layouts to that wrapper layout. You should also define a width of 100% for the vl5 layout so it will span the entire width of the row:

if (action == Action.ADD) {
                            
    VerticalLayout vl5 = new VerticalLayout();
    // add width to layout
    vl5.setWidth("100%")
                            
    Label title = new Label(movie.getTitle());
    Label description = new Label(movie.getDescription());
    Label director = new Label(movie.getDirector());
                            
    vl5.addComponent(title);
    vl5.addComponent(description);
    vl5.addComponent(director);
    
    // Insert to the wrapper layout here:
    rightLayout.addComponent(vl5);    
    movieManager.addMovie(movie);
}
Daniel Bojarski
6 years ago Oct 24, 2015 8:42pm

Max Schuster: Hi Daniel,

the CustomLayout can only add one Component per slot. So if you want to add more than one Component to the slot, you'll need another VerticalLayout that holds your vl5 layouts:

CustomLayout CL = new CustomLayout([...]);
VerticalLayout rightMenu = new VerticalLayout();
rightMenu.setWidth("100%");
CL.addComponent(rightMenu , "right_menu");

And than add your vl5 layouts to that wrapper layout. You should also define a width of 100% for the vl5 layout so it will span the entire width of the row:

if (action == Action.ADD) {
                            
    VerticalLayout vl5 = new VerticalLayout();
    // add width to layout
    vl5.setWidth("100%")
                            
    Label title = new Label(movie.getTitle());
    Label description = new Label(movie.getDescription());
    Label director = new Label(movie.getDirector());
                            
    vl5.addComponent(title);
    vl5.addComponent(description);
    vl5.addComponent(director);
    
    // Insert to the wrapper layout here:
    rightLayout.addComponent(vl5);    
    movieManager.addMovie(movie);
}

Hello

Thank you for your answer but I'm afraid it's not what I wanted to know. Do thanks to that I'll be able to add the same component few times? (by saying "the same" i mean with the same name). I want to get a resault like with table columns generator where all added objects can be displayed in a table. Here I want to display all objects data not in a table but in layouts (something like creating the layouts dynamiclly), something like multiplying.

Sorry in advance for mistakes, english is not my native language :) Cheers

I've checked it! It works really well! Thank you, you're awesome! :)

Max Schuster
6 years ago Oct 24, 2015 9:30pm

Daniel Bojarski:

Max Schuster: Hi Daniel,

the CustomLayout can only add one Component per slot. So if you want to add more than one Component to the slot, you'll need another VerticalLayout that holds your vl5 layouts:

CustomLayout CL = new CustomLayout([...]);
VerticalLayout rightMenu = new VerticalLayout();
rightMenu.setWidth("100%");
CL.addComponent(rightMenu , "right_menu");

And than add your vl5 layouts to that wrapper layout. You should also define a width of 100% for the vl5 layout so it will span the entire width of the row:

if (action == Action.ADD) {
                            
    VerticalLayout vl5 = new VerticalLayout();
    // add width to layout
    vl5.setWidth("100%")
                            
    Label title = new Label(movie.getTitle());
    Label description = new Label(movie.getDescription());
    Label director = new Label(movie.getDirector());
                            
    vl5.addComponent(title);
    vl5.addComponent(description);
    vl5.addComponent(director);
    
    // Insert to the wrapper layout here:
    rightLayout.addComponent(vl5);    
    movieManager.addMovie(movie);
}

Hello

Thank you for your answer but I'm afraid it's not what I wanted to know. Do thanks to that I'll be able to add the same component few times? (by saying "the same" i mean with the same name). I want to get a resault like with table columns generator where all added objects can be displayed in a table. Here I want to display all objects data not in a table but in layouts (something like creating the layouts dynamiclly), something like multiplying.

Sorry in advance for mistakes, english is not my native language :) Cheers

Hi Daniel,

english isn't my native language, too ;)
But I think I've got your point right with my first answer, but "The code is documentation enough" didn't work this time :P
I was trying to explain that you should create a wrapper layout and add it to the "right_menu" slot of your CustomLayout. And when your Button is clicked you want to add the new movie VerticalLayout instances to the wrapper layout instead of the CustomLayout instead. This way you are able to add as many movie VerticalLayouts as you want.

So your component hierarchy will look like this:
CL (CustomLayout)
| -- rightMenu (VerticalLayout)
      | -- movieLayout (VerticalLayout)
      | -- movieLayout (VerticalLayout)
      | -- ...