layying some buttons assigning to each of them the width of the largest

Hi,
Does somebody know how to layout some buttons assigning to each of them the width of the one that has the large caption?

Using uniform expansion ratio strategy I need to set the width of the layout (= toolbar button) to a fixed size (let’s say 700px), which I want to avoid if possible.

		MyButton btn1 = new MyButton(titBtn1, this, "googleBtnClick");	
		 	btn1.addStyleName("first");
		 	btn1.setWidth("100%");

		MyButton btn2 = new MyButton(titBtn2);
			btn2.setWidth("100%");

		MyButton btn3 = new MyButton(titBtn3);
			btn3.setWidth("100%");
		 			 	
		MyButton btn4 = new MyButton(titBtn4, this, "logoutBtnClick");
		 	btn4.addStyleName("last");
		 	btn4.setWidth("100%");
		 	
		mainLayout = new HorizontalLayout();				
			mainLayout.addComponent(btn1);
			mainLayout.addComponent(btn2);		
			mainLayout.addComponent(btn3);
			mainLayout.addComponent(btn4);	
			mainLayout.setStyleName("segment");
			mainLayout.addStyleName("segment-alternate");
			mainLayout.setExpandRatio(btn1, 1.0f);
			mainLayout.setExpandRatio(btn2, 1.0f);
			mainLayout.setExpandRatio(btn3, 1.0f);
			mainLayout.setExpandRatio(btn4, 1.0f);
			mainLayout.setWidth("700px");

thanks!
11789.png

I tested your code and it seems to me just changing the “700px” to “100%” works, with or without setting the expand ratios - or at least it does in my simple test case where buttons are normal Vaadin Buttons. Is there anything in your MyButton or styles that might interfere?

Edit: sorry, didn’t read your question properly to start with - you probably wanted a solution that doesn’t involve stretching the buttons to the full width of the page. You could probably manage that with giving your buttons widths based on the max length of their captions and multiplying that with some suitable amount of pixels, but that’s nowhere near an elegant solution. I hope someone else has better ideas.

Ja!, it seems that framework doesn’t provide something to avoid developer elaborate solution based in calculating the width of the largest button caption and assigning it to others.
Thank you anyway Anna.