Bug: HorizontalLayout ExpandRatio suppresses Label


Maybe there is a bug here…
When exists labels in a horizontal layout and there is another component expanded in the same layout, the label is suppressed.

public class ExampleApp extends Application {

	public void init() {
		setMainWindow(new MainWindow());

	class MainWindow extends Window {

		public MainWindow() {
			HorizontalLayout horizontalLayout = new HorizontalLayout();
			horizontalLayout.addComponent(new Button("Button"));
			horizontalLayout.addComponent(new Label("Label"));
			TextField txtField = new TextField();
			txtField.setInputPrompt("Texfield expanded");
			horizontalLayout.setExpandRatio(txtField, 1.0f);

That’s because all Labels are 100% wide by default and relative sized components with expand ratio of zero will be zero sized (setting the expand ratio on only one widget in the layout sets the remaining expand ratios to zero).

So you need to call Label.setWidth(null) for the label in question in order for it to show up. Or alternatively set an expand ratio for it.

Thanks Jouni, setting label width to null solve my problem!