2017-02-28 75 views
1

如何獲取GXT中窗口的X位置?我可以使用setPosition設置位置。但由於沒有得到方法,我無法得到這個位置。你能幫我找回一個窗口的位置嗎?如何在gxt中獲取窗口的x位置

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

回答

0

你可以得到,作爲在GWT的每一個元素,該元素與位置:

/** 
* 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(); 

/** 
* 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(); 

兩種方法都在GWT,UIObject類的一部分GWT 2中的每個小部件都繼承。

希望有所幫助。

+0

我總是得到0 getAbsoluteLeft()和getAbsoluteTop() – user2207

+0

小部件必須附加到DOM以獲得它的位置。 –