[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


How to properly obtain screen dimensions in GWT?

Posted on 2012-08-17
Medium Priority
Last Modified: 2012-08-23
How do I properly obtain screen dimensions for the RootPanel of the browser screen?
Would using say:
and calling:
HTML htmlObj;
int myHeight= htmlObj..getOffsetHeight();
int myWidth=htmlObj.getOffsetWidh();

I would appreciate any help here ???
Question by:Robert Silver
  • 3

Author Comment

by:Robert Silver
ID: 38312177
Note when I try to obtain the Height offset
e.g  rootPanel.getOffsetHeight()   I get 0 . Why? How do I obtain the actual screen height potentially?? A bit more research shows that this is a programmable number
e.g if I rootPanel.setSize("100%","2000px");   the getOffsetHeight uses that size.
By default I would have thought the default getOffsetHeight() would be the physical size possible of a  graphic on a given screen e.g Android might be 400px by 640px maybe and
I could then get those values. How might I get the physical for device height in pixels then?

Accepted Solution

Robert Silver earned 0 total points
ID: 38314153
I may have answered my own question here.
The getOffsetHeight returns a value after setting size to 100% 100% if and only if so far
the method call: rootPanel.getElement().getStyle().setPosition(Position.ABSOLUTE);
is executed before setting the size. After setting the size e.g rootPanel.setSize("100%","100%");  a value was indeed returned.

Author Comment

by:Robert Silver
ID: 38325293
Well I found out something else everyone here should know. Microsoft Internet Explorer does not work well with Absolute positioning within GWT. Please let me know if you find a way to use Absolute positioning. I ultimately set Absolute positioning with the statement:
Then get the the Offsets e.g
getOffsetHeight() and getOffSetWidth() and they both return proper values to be used,however, I must set rootPanel.getElement().getStyle().setPosition(Position.RELATIVE);
and then provide relative positioning to solve the cross browser needs.
Note GWT is no longer supported by Firefox 14 latest addition at the time of this writing nor is it supported by Opera or Safari. Only IE and Google Chrome and the Chrome is a pain to install GWT now. drag and drop nonsense has to be done in a prescribed maner due to some ill conceived security constraints.
Just updating my previous solution.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
There is a lot to be said for protecting yourself and your accounts with 2 factor authentication.  I found to my own chagrin, that there is a big downside as well.
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question