Directory

← Back

SizeReporter

SizeReporter gives you the size of any component in the browser

Author

Rating

Popularity

<100

By default, component sizes in the browser are not reported back to the server. This extension allows you to get the actual component size in pixels for any component and to listen for size changes.

Sample code

import com.ejt.vaadin.sizereporter.ComponentResizeEvent;
import com.ejt.vaadin.sizereporter.ComponentResizeListener;
import com.ejt.vaadin.sizereporter.SizeReporter;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.*;

import java.util.Date;

public class TestUi extends UI{
    @Override
    protected void init(VaadinRequest request) {
        final VerticalLayout layout = new VerticalLayout();
        layout.setMargin(true);
        layout.setSpacing(true);

        final Panel panel = new Panel();
        panel.setContent(new Label("Why do you want to know my size?"));
        panel.setWidth("100%");
        layout.addComponent(panel);

        final Label sizeLabel = new Label();
        layout.addComponent(sizeLabel);

        Button button = new Button("Add single use size reporter");
        layout.addComponent(button);
        button.addClickListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                new SizeReporter(panel).addResizeListenerOnce(new ComponentResizeListener() {
                    @Override
                    public void sizeChanged(ComponentResizeEvent event) {
                        layout.addComponent(new Label("Panel size at " + new Date() + ": " + event.getWidth() + " x " + event.getHeight()));
                    }
                });
            }
        });

        SizeReporter sizeReporter = new SizeReporter(panel);
        sizeReporter.addResizeListener(new ComponentResizeListener() {
            @Override
            public void sizeChanged(ComponentResizeEvent event) {
                sizeLabel.setValue("Panel size: " + event.getWidth() + " x " + event.getHeight());
            }
        });

        setContent(layout);
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Sizes were not reported for elements that were loaded, such as com.vaadin.ui.Image

Released
2015-05-04
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.0+
Vaadin 8.0+
Browser
N/A

SizeReporter - Vaadin Add-on Directory

SizeReporter gives you the size of any component in the browser SizeReporter - Vaadin Add-on Directory
By default, component sizes in the browser are not reported back to the server. This extension allows you to get the actual component size in pixels for any component and to listen for size changes.
Online