2013-10-24 133 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以防止窗口移出屏幕。