2

Im facing overlaps problem with my project when trying to resize browser. I was trying so many different variations to make it work, but still result is not acceptable.

Before resizing: enter image description here

A, B and C are contained in VerticalLayout - I will call it root.

Now, when Im trying to resize my browser (like arrow shows) C is starting to steal other components place.

After resizing: enter image description here

The effect I would like to achieve is that my Grid (C) is not trying to fit my browser. It should not move, and just hide - like below (green is showing actually visible part):

effect I would like to achieve

    /*ROOT class that extends VerticalLayout*/
    private void init()
    {
        super.setSizeFull();

        addA();
        addB();
        addC();
    }

    private void addA()
    {
        Label header = new Label();

        super.addComponent(header);
        super.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
    }

    private void addB()
    {
        layoutB.setSizeFull();
        layoutB.setWidth("92%");
        super.addComponentsAndExpand(layoutB);
        super.setExpandRatio(layoutB, 0.3f);
        super.setComponentAlignment(layoutB, Alignment.MIDDLE_CENTER);
    }

    private void addC()
    {
        grid.setSizeFull();
        grid.setColumnReorderingAllowed(true);

        grid.setWidth("92%");
        super.addComponentsAndExpand(grid);
        super.setExpandRatio(grid, 0.6f);
        super.setComponentAlignment(grid, Alignment.BOTTOM_CENTER);
    }

As you can see C is added in the same way as B, but only C is moving. Thanks in advance for any help!

Im using Vaadin 8.

@Edit:

@SpringUI(path = "/ui")
public class MyUI extends UI {

@Override
protected void init(VaadinRequest request) 
{
    Workspace workspace = new Workspace();

    HorizontalLayout root = new HorizontalLayout();
    root.setSizeFull();
    root.addComponentsAndExpand(workspace);

    setContent(root);
}

public class Workspace extends Panel
{
    public Workspace()
    {
        init();
    }

    private void init()
    {
        setSizeFull();
        addStyleName(ValoTheme.PANEL_BORDERLESS);

        VerticalLayout layout = new VerticalLayout();
        // by default width 100% and height undefined in Vaadin 8
        setContent(layout);

        // component A
        Label label = new Label("Test1");
        layout.addComponent(label);

        // component B
        HorizontalLayout bar = new HorizontalLayout();
        bar.addComponents(new Label("Label 1"), new Label("Label 2"));
        layout.addComponent(bar);

        // component C
        Grid<MyBean> grid = new Grid<>(MyBean.class);
        grid.setCaption("My Grid:");
        grid.setHeight("1000px");
        //grid.setHeightByRows(50); // same as fixed height
        List<MyBean> items = new LinkedList<>();
        IntStream.range(1, 100).forEach(i -> items.add(new MyBean("Item " + i)));
        grid.setItems(items);
        layout.addComponent(grid);
    }
}

    public static class MyBean {
        private String name;
        public MyBean(String name) { this.name = name; }
        public String getName() { return name; }
        public void setName(String name) { this.name = name; }
    }

}
Dawid Fieluba
  • 1,271
  • 14
  • 34
  • 1
    First of all, I wouldn't recommend to subclass `VerticalLayout` when you don't extend it - just create a new instance and add your components. Your problem should be the full sized vertical layout. Please try wrapping it in a full sized `Panel`, then make your vertical layout full width and undefined height. The other components in your vertical layout should have undefined height, too. This will make it grow in height as needed. – Steffen Harbich Sep 14 '17 at 06:58
  • I tried doing this, but its behaviour is the same, no matter if I wrap my `VerticalLayout` in `Panel`. I think this problem is initialized in one level above and depends on `HybridMenu` content - [more](https://stackoverflow.com/questions/46196816/vaadin-hybridmenu-shift-with-scrollpanel?noredirect=1#comment79387948_46196816). If `HybridMenu` content height is not full it works as I want, but then scrollpanel is not working properly. – Dawid Fieluba Sep 14 '17 at 07:50
  • 1
    Did you test it without the HybridMenu? Can you post the full code with the panel? – Steffen Harbich Sep 14 '17 at 07:58
  • Yep, firstly it was without `HybridMenu`. Looks like level above cannot be fullSized. Now I see that, if both `HybridLayout` **content** and `HybridLayout` are fullsized - overlaps problem occurs. If only 1 of them is fullsized its fine, but then I can't scroll. – Dawid Fieluba Sep 14 '17 at 08:12

1 Answers1

1

Have a look at this working example:

@SpringUI(path = "/ui")
public class MyUI extends UI {

@Override
protected void init(VaadinRequest request) {
    Panel panel = new Panel();
    panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
    panel.setSizeFull();

    VerticalLayout layout = new VerticalLayout();
    // by default width 100% and height undefined in Vaadin 8
    panel.setContent(layout);

    // component A
    Label label = new Label("Test1");
    layout.addComponent(label);

    // component B
    HorizontalLayout bar = new HorizontalLayout();
    bar.addComponents(new Label("Label 1"), new Label("Label 2"));
    layout.addComponent(bar);

    // component C
    Grid<MyBean> grid = new Grid<>(MyBean.class);
    grid.setCaption("My Grid:");
    grid.setHeight("1000px");
    //grid.setHeightByRows(50); // same as fixed height
    List<MyBean> items = new LinkedList<>();
    IntStream.range(1, 100).forEach(i -> items.add(new MyBean("Item " + i)));
    grid.setItems(items);
    layout.addComponent(grid);

    setContent(panel);
}

public static class MyBean {
    private String name;
    public MyBean(String name) { this.name = name; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
}

}

The Grid has a fixed height (either by pixels or by number of rows). No expand ratios are necessary for the VerticalLayout. The layout within the Panel will grow as needed by its child components. If the height is greater than the space available for the Panel then scroll bars are shown.

Steffen Harbich
  • 2,639
  • 2
  • 37
  • 71
  • Well it also works for me when I do it this way but problem occurs when `Panel` is not setted directly as `UI` content. Could you please try with one more level? Like inserting Panel into `HorizontalLayout` which is content of `UI`. I see that I missed this in question, cuz I was sure there is no connection. – Dawid Fieluba Sep 14 '17 at 11:27
  • 1
    It will be easier if you modify my example and post it again. – Steffen Harbich Sep 14 '17 at 11:32
  • I tried your code, but I can't see any problems. What exactly is not working? A potential problem is that the `HorizontalLayout` is not of full height (100%). You can see that in the [client debug window](https://vaadin.com/docs/-/part/framework/advanced/advanced-debug.html#advanced.debug.hierarchy.analyze) of Vaadin. – Steffen Harbich Sep 15 '17 at 06:33
  • Yep, Im sorry, I forgot setting `HorizontalLayout` to fullsize. Can u see overlapsing of components now? – Dawid Fieluba Sep 15 '17 at 07:01
  • No, I resized window (firefox), no overlapping or other layout problems. Can you provide some screenshots? – Steffen Harbich Sep 15 '17 at 08:14
  • I tested it with firefox, and result is the same. I've added screenshots. – Dawid Fieluba Sep 15 '17 at 08:41
  • 1
    The screenshots show your application. Did you reproduce the issue with my example code that you modified? If yes add screenshots for that, if no I can only help you if you provide the whole code that is necessary to reproduce the issue on my machine. – Steffen Harbich Sep 15 '17 at 09:03
  • Okay, your example works perfectly. I will have to work on my own at this moment. There is nothing more you can help me. PS. My grid causes problem – Dawid Fieluba Sep 15 '17 at 09:08