Notify parent about size change necessary?

Hi,

My CustomComponent uses a GridLayout. It contains a Label with .setValue(“short”) and .setWidth(null).
When I do a .setValue(“verylongstring”) the CustomComponent grows “to the right” and is truncated.

How does a CustomComponent notify its parent that the size has changed?

Thanks,
Roland

A Label with undefined width will not wrap around to multiple lines, so if it is too long, it will overflow. If you want wrapping, you need to do setWidth(“100%”).

I’m not exactly sure what your situation is, does the GL and the CustomComponent have 100% width? Are there other columns? Expand ratios?

Yes, CustomComponent informs the parents of size changes.

A
related example
.

Thanks for your reply and sorry for not making myself clear. I attach a test application.
When you click on the button, the button is pushed out of the window by the label.

Thanks,
Roland
11821.java (2.07 KB)

Ok… I tried out the code and looks like there’s a problem with the GridLayout. The code works if you replace the GridLayout with HorizontalLayout. I think your example was missing the “label.setWidth(null)” in the constructor, as done below. Also, the buildMainLayout() was a bit odd place to make settings to the CustomComponent itself, not to the main layout. Well, the Grid-/HorizontalLayout has undefined size by default, so it’s not actually needed.

    public class MyComponent extends CustomComponent implements Button.ClickListener{
        private static final long serialVersionUID = 2410031296406771262L;
        private HorizontalLayout mainLayout;
        private Label label;
        public MyComponent() {
            setSizeUndefined();

            buildMainLayout();
            setCompositionRoot(mainLayout);

            label = new Label("short");
            label.setWidth(null);
            Button button = new Button("Click");
            
            mainLayout.addComponent(label);   
            mainLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
            mainLayout.addComponent(button);  
            button.addListener(this);
            
        }   
        private HorizontalLayout buildMainLayout() {
            mainLayout = new HorizontalLayout();
            mainLayout.setSizeUndefined();
            return mainLayout;
        }
        public void buttonClick(ClickEvent event) {
            label.setValue("12345678901234567890");
        }
    }

There were some GridLayout column sizing tickets previously, but possibly unrelated, so created
#7326
.