Cant get HorizontalLayout work with Space between Elements

Hi,

i am Trying to Build a Ribbon-Like Menubar.
Therefor i created a HorizontalLayout. Then i have 2 Buttons and every Button is Wrapped in a Panel.
Now i want to have the Horizontal Layout with with 100% on the Full screen, what works perfect.
But Now i add the Two Buttons and i want to one button on the full left side and the other button on the full right side.

Like this:
B Space B
But in what ever way i try to add this, the Panels are Streched and it is not realy Working.

Someone tried something like this ?

Thanks for any help.

One way would be to use an “empty” Label as placeholder:

final HorizontalLayout hlayout = new HorizontalLayout();
hlayout.setWidth("100%");
setContent(hlayout); 
Panel p1 = new Panel("test1");
p1.setWidth("50px");
hlayout.addComponent(p1);

Label l = new Label("&nbsp");
l.setContentMode(ContentMode.HTML);
l.setWidth("100%");
hlayout.addComponent(l);

Panel p2 = new Panel("test2");
p2.setWidth("50px");
hlayout.addComponent(p2);

hlayout.setExpandRatio(l, 1f);
hlayout.setExpandRatio(p1, 0);
hlayout.setExpandRatio(p2, 0);

Another would be to attach a style to the right panel containing:

position: absolute;
right: 0px;

You can use expand ratio and also do
layout.setComponentAlignment(component, alignment);

you will get all the alignment proper i suppose

Right, i totally forgot about setComponentAlignment.
So a third option would be:

final HorizontalLayout hlayout = new HorizontalLayout();
hlayout.setWidth("100%");
setContent(hlayout); 

Panel p1 = new Panel("test1");
p1.setWidth("50px");
hlayout.addComponent(p1);

Panel p2 = new Panel("test2");
p2.setWidth("50px");
hlayout.addComponent(p2);

hlayout.setComponentAlignment(p2, Alignment.MIDDLE_RIGHT);

Thanks i dislike the theo of the specific with of XXpx.
I wanted to have the Panels dynamically.
Therefore I now wrapped each Panel in a separate Layout (left and right) and set the alignment to left and right.
Then i added the Layouts to my Masterlayout.

Thanks All.