How to get root and active window size

Hi.

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
screen.getOpenedScreens().getRootScreenOrNull().getWindow().getHeight();
screen.getOpenedScreens().getRootScreenOrNull().getWindow().getHeightSizeUnit().toString();

but the result in 100% not px

An example would be good.
Thanks

Hi,

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

public class Sandbox extends Screen {
    @Autowired
    private Notifications notifications;

    @Subscribe
    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) {
        notifications.create()
                .withCaption("Width: " + width + " Height: " + height)
                .show();
    }
}

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

Gleb

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