Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

How to determine the browser's size?

Tipsija Ducija
1 decade ago Aug 26, 2010 1:47am
Jouni Koivuviita
1 decade ago Aug 26, 2010 6:03am

Hi,

Have you tried getting the size of the main window of your application? I'm not sure, but it could provide this information.

Henri Sara
1 decade ago Aug 26, 2010 6:15am
Tipsija Ducija
1 decade ago Aug 26, 2010 10:45am
Sergio Mejia
1 decade ago Oct 21, 2011 3:46pm

i've found this end works

int Height=600;
int Width=800;

ApplicationContext context = this.getContext();
if (context instanceof WebApplicationContext) {
Heigth= ((WebApplicationContext)this.getContext()).getBrowser().getScreenHeight();
Width = ((WebApplicationContext)this.getContext()). getBrowser().getScreenWidth();
}

Frithjof Schaefer
10 years ago Mar 25, 2013 12:11pm

I didn't found the answer anywhere. If you really need the Size of the browser window, your vaadin app is running in, use this code:

com.vaadin.ui.AbstractComponent instance = ....;
.....
int w = instance.getApplication().getMainWindow().getBrowserWindowWidth();
int h = instance.getApplication().getMainWindow().getBrowserWindowHeight();
Erik Hansen
10 years ago Apr 11, 2013 10:22am

Or even easier

UI.getCurrent().getPage().getBrowserWindowWidth();
UI.getCurrent().getPage().getBrowserWindowHeight();

Frithjof Schaefer: I didn't found the answer anywhere. If you really need the Size of the browser window, your vaadin app is running in, use this code:

com.vaadin.ui.AbstractComponent instance = ....;
.....
int w = instance.getApplication().getMainWindow().getBrowserWindowWidth();
int h = instance.getApplication().getMainWindow().getBrowserWindowHeight();