我正在寻找一个简单的解决方案来解决我的 GWT DialogBox
可以拖出屏幕的问题。主机具有 CSS 规则 overflow:hidden
因为我不希望出现任何滚动条。
显然,我需要以某种方式将监听器附加到拖动上,并防止将其带出外部的移动。我只能在 DialogBox
中看到 onMouseMove
、beginDragging
、endDragging
方法。
最佳答案
“我们”通过以下方式解决了这个问题:
@Override
protected void endDragging(MouseUpEvent event)
{
int genericMargin = 60;
int leftMargin = -(this.getOffsetWidth() - genericMargin);
int lowerMargin = Window.getClientHeight() - genericMargin;
int rightMargin = Window.getClientWidth() - genericMargin;
int upperMargin = 0;
if (this.getAbsoluteLeft() > rightMargin)
{this.setPopupPosition(rightMargin, this.getPopupTop()); }
if (this.getAbsoluteLeft() < leftMargin)
{ this.setPopupPosition(leftMargin, this.getPopupTop()); }
if (this.getAbsoluteTop() > lowerMargin)
{ this.setPopupPosition(this.getPopupLeft(), lowerMargin);}
if (this.getAbsoluteTop() < upperMargin)
{ this.setPopupPosition(this.getPopupLeft(), upperMargin);}
super.endDragging(event);
}
顺便说一句,它可以正常工作! ;)
关于java - 如何防止GWT对话框被拖出屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12211331/