Search code examples
javagwtwindowgxt

how to get x y position of a window in gxt


How to get X Y position of a window in GXT? I am able to set the position using setPosition. But I am not able to get the position as there is not get method. Can you please help me in retrieving the position of a window?

Window window = new Window();
window.setClosable(true);
window.setWidth(300);
window.setHeight(300);
window.setPosition(30, 50);

Solution

  • You can get, as for every element in GWT, the element's position with:

    /**
     * Gets the object's absolute left position in pixels, as measured from the
     * browser window's client area.
     * 
     * @return the object's absolute left position
     */
    window.getAbsoluteLeft();
    

    and

    /**
     * Gets the object's absolute top position in pixels, as measured from the
     * browser window's client area.
     * 
     * @return the object's absolute top position
     */
    window.getAbsoluteTop();
    

    Both methods are part of the UiObject class in GWT, which every widget in GWT 2 inherits.

    Hope that helps.