Search code examples
vaadin7

vaadin7 with two HorizontalLayout one on the right


I have HorizontalLayout and in it combo c1 and c2:

    HorizontalLayout hrzLy1 = new HorizontalLayout();
    mainVertical.addComponent(hrzLy1);
    hrzLy1.setWidth("100%");

    ComboBox c1 = new ComboBox("combo1");
    hrzLy1.addComponent(c1);
    c1.setWidth("100%");

    ComboBox c2 = new ComboBox("combo2");
    hrzLy1.addComponent(c2);
    c2.setWidth("40px");

I would like c2 to be on the right and have just 40px width. c1 should occupy all the left side of the window. I have try with setComponentAlignment but can not get c1 widther and setExpandRatio but when I maximize window, the c2 is not completely on the right, looks like ratio should be changed in case of the window size change, so I guess ratio is not a solution. I have try with GridLayout but I can not set first cell on 100% and second 40px. Please help out.


Solution

  • I think what you want can be achieved by using expand ratio and a full sized c1 - giving expand ratio 1 to the full sized combobox. (but I think I don't fully get what the problem was when you tried it).

    Here is what I tried which seems to work like what you want to achieve:

    HorizontalLayout hrzLy1 = new HorizontalLayout();
    hrzLy1.setWidth("100%");
    
    ComboBox c1 = new ComboBox("combo1");
    c1.setSizeFull();
    
    ComboBox c2 = new ComboBox("combo2");
    c2.setWidth("40px");
    
    hrzLy1.addComponents(c1,c2);
    hrzLy1.setExpandRatio(c1, 1.0f);
    

    Tested within Vaadin 7.7.13 and a full sized vertical layout as UI content.

    enter image description here