How to properly obtain screen dimensions in GWT?

Posted on 2012-08-17
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
    LVL 2

    Author Comment

    by:Robert Silver
    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?
    LVL 2

    Accepted Solution

    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.
    LVL 2

    Author Comment

    by:Robert Silver
    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Specialist

    HTML5 development skills are critical to all developers. HTML5 is the foundation to almost any development process. That's why business, design studios, development shops and other organizations need HTML5 developers. Get your foot in the door as a HTML5 specialist.

    Suggested Solutions

    Title # Comments Views Activity
    Multiple issues with Java 14 37
    mergeTwo  challenge 13 53
    count11 challenge 6 30
    where is session ID cache stored 1 25
    In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
    Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now