2013-10-24 134 views
0

所有對話窗口都可以在屏幕之外移動(水平或垂直,無所謂)。當此窗口位於屏幕後方時,可以繼續進一步拖動,屏幕內容將移動。GWT:防止對話框移出屏幕

這聽起來很難理解,但最終它看起來像這樣: enter image description here

css以下更改不會有很大的幫助:

body { 
    ... 
    position: absolute; 
    top: 0; 
    left: 0; 
    bottom: 0; 
    right: 0; 
    overflow-y: hidden; 
    overflow-x: hidden; 
    ... 
} 


html { 
    overflow-y: hidden; 
    background-color: transparent; 
} 

垂直和水平滾動條唐當對話窗口移到那裏時不會出現。但是,如果有一個對話窗口的尺寸大於主屏幕,則滾動條也不會出現 - 這是另一個問題。

如何防止對話窗口移出屏幕(快速示例,谷歌驅動器中的對話窗口 - 他們只在屏幕的可見部分移動)?

+0

這是你需要的嗎? http://stackoverflow.com/questions/12211331/how-to-prevent-gwt-dialogbox-from-being-dragged-out-of-the-screen –

+0

@sᴜʀᴇsʜᴀᴛᴛᴀ,它不適合我。我自己實現了'endDragging'(請參閱我的答案)。 – Dragon

回答

0

我來解決我正在尋找通過覆蓋endDragging DialogBox的方法。它是:

@Override 
protected void endDragging(MouseUpEvent event) 
{ 
    //Move dialog window behind top border 
    if(this.getAbsoluteTop() < 0) { 
     this.setPopupPosition(this.getPopupLeft(), 0); 
    } 
    //Move dialog window behind bottom border 
    if(this.getAbsoluteTop() > (Window.getClientHeight() - this.getOffsetHeight())) { 
     this.setPopupPosition(this.getPopupLeft(), Window.getClientHeight() - this.getOffsetHeight()); 
    } 

    //Move dialog window behind left border 
    if(this.getAbsoluteLeft() < 0) { 
     this.setPopupPosition(0, this.getPopupTop()); 
    } 
    //Move dialog window behind right border 
    if(this.getAbsoluteLeft() > (Window.getClientWidth() - this.getOffsetWidth())) { 
     this.setPopupPosition(Window.getClientWidth() - this.getOffsetWidth(), this.getPopupTop()); 
    } 
    super.endDragging(event); 
} 

當對話框移出屏幕時,它會在鼠標釋放後出現在屏幕的可見部分。可以改進它並覆蓋continueDragging以防止窗口移出屏幕。