How to get root and active window size


I need some help.

I’m trying to find out the size in px of :

  • current page: innerWidth, innerHeight, width, height
  • root width, height

I tried

but the result in 100% not px

An example would be good.


The only thing that is accessible from UI server-side is browser window size:

public class Sandbox extends Screen {
    private Notifications notifications;

    public void onInit(InitEvent event) {
        Page page = UI.getCurrent().getPage();

        showSize(page.getBrowserWindowWidth(), page.getBrowserWindowHeight());

        page.addBrowserWindowResizeListener(resizeEvent ->
                showSize(resizeEvent.getWidth(), resizeEvent.getHeight()));

    private void showSize(int width, int height) {
                .withCaption("Width: " + width + " Height: " + height)

If you describe your task, I’ll be possibly able to suggest a solution.


From an window with forceDialod=“true”, I try to open a new window, forceDialog=“true”.
The position of the first window is set manualy and I thy to calculate a position for the second window based on browser size and first window position.

Seems that info from UI.getCurrent().getPage() is sufficient for your purpose.

1 Like

It works !
Thank you