Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin - Expand components in Grid Layout in Vaadin

I am doing my project in Vaadin 6. In that, I have integrated the components in a Grid layout. I have attached a image with this. It resembles my Project layout. It is similar to eclipse. So, The layout will have two side panels on left and right. and a center and bottom panel. And the red color in the image are buttons. When I press them the panel will be minimized. I want the center panel to expand and occupy the minimized panel's area. I have integrated the panels in grid layout. Can anyone tell me how to expand a component in the grid layout.

When I minimize 'R'; 'C' & 'B' have to occupy it's area.

When I minimize 'B'; 'C' have to occupy it's area.

When I minimize 'L'; 'C' & 'B' have to occupy it's area. layout

like image 486
Gugan Avatar asked Mar 11 '13 09:03

Gugan


People also ask

How do I increase the size of my grid layout?

Put your GridLayout on its own JPanel, and then you can use panel. setSize(x,y) to change the panel size and thus increase or decrease the size of the cells.

How do you make a grid in vaadin?

// Have some data List<Person> people = Arrays. asList( new Person("Nicolaus Copernicus", 1543), new Person("Galileo Galilei", 1564), new Person("Johannes Kepler", 1571)); // Create a grid bound to the list Grid<Person> grid = new Grid<>(); grid. setItems(people); grid. addColumn(Person::getName).

What is a grid component?

The grid component There are two types of grid components: containers and items. To make the layout fluid and adaptive to screen sizes, the item widths are set in percentages. Padding creates spacing between individual items. Finally, there are five types of grid breakpoints: xs , sm , md , lg , and xl .

How do I add a button in grid vaadin?

Vaadin 8.1 now has a built-in ComponentRenderer for displaying buttons or other components including your own custom components in a Grid. See first item "Components in Grid" on What's New page. Example: Add a label to a grid. Save this answer.


2 Answers

Here a working example without additional add-on. You can use horizontal and vertical layout.

public class TestUI extends UI {

    Panel L = new Panel();
    Panel C = new Panel();
    Panel B = new Panel();
    Panel R = new Panel();

    Button bL = new Button("Toggle L", new CloseButtonHandler(L));
    Button bC = new Button("Toggle C", new CloseButtonHandler(C));
    Button bB = new Button("Toggle B", new CloseButtonHandler(B));
    Button bR = new Button("Toggle R", new CloseButtonHandler(R));

    @Override
    protected void init(VaadinRequest request) {
        L.setWidth("80px");
        L.setHeight("100%");
        L.setContent(new Label("L"));
        R.setWidth("80px");
        R.setHeight("100%");
        R.setContent(new Label("R"));
        B.setHeight("80px");
        B.setWidth("100%");
        B.setContent(new Label("B"));
        C.setHeight("100%");
        C.setHeight("100%");
        C.setContent(new Label("C"));

        VerticalLayout vl = new VerticalLayout();
        vl.addComponent(C);
        vl.addComponent(B);
        vl.setExpandRatio(C, 1);
        vl.setSizeFull();

        HorizontalLayout hl = new HorizontalLayout();
        hl.addComponent(L);
        hl.addComponent(vl);
        hl.addComponent(R);
        hl.setExpandRatio(vl, 1);
        hl.setSizeFull();

        CssLayout root = new CssLayout();
        root.addComponent(bL);
        root.addComponent(bC);
        root.addComponent(bB);
        root.addComponent(bR);
        root.addComponent(hl);
        root.setSizeFull();

        setContent(root);
    }

    private class CloseButtonHandler implements ClickListener {
        private Panel layout;

        public CloseButtonHandler(Panel layout) {
            this.layout = layout;
        }

        @Override
        public void buttonClick(ClickEvent event) {
            layout.setVisible(!layout.isVisible());
        }
    }
}

The example is for Vaadin 7 but the concept should work with Vaadin 6 too.

like image 109
raffael Avatar answered Oct 10 '22 19:10

raffael


Raffel's answer is the best and quickest solution for this question. But, I had some Project structure problem in implementing it.

I did it in my way. Resizing Components in Grid layout seem to be a difficult. So, I moved to Vertical, and horizontal layouts.

I set 'C' and 'B' in Vertical Layout called 'VL'. And I set 'L' and 'VL' and 'R' in a Horizontal Layout called 'HL'. And I added buttons to toggle wherever I needed. Whenever I press any toggle button, It will hide the layout. I achieved it by redefining the

 setExpandRatio();

When a toggle button is pressed, I redefined the setExpandRation() for that component. And again when the button is pressed again I reset the setExpandRatio() to older value. This idea works well in all size monitors.

like image 30
Gugan Avatar answered Oct 10 '22 18:10

Gugan