Java 如何防止GWT对话框被拖出屏幕?
我正在寻找一个简单的解决方案,可以将我的GWTJava 如何防止GWT对话框被拖出屏幕?,java,gwt,Java,Gwt,我正在寻找一个简单的解决方案,可以将我的GWT对话框拖出屏幕。主机具有CSS规则溢出:隐藏,因为我不希望出现任何滚动条 显然,我需要以某种方式为拖拽添加一个侦听器,以防止将拖拽带到外部的移动。我只能在对话框中看到onMouseMove,beginDragging,endDragging方法,我建议尝试gwtquery dnd。我一直在使用拖放插件,效果非常好。它有一个选项setContianment(Element elem),这是您正在寻找的。其他一些特性是,它有snap,所以如果您希望将对话
对话框
拖出屏幕。主机具有CSS规则溢出:隐藏
,因为我不希望出现任何滚动条
显然,我需要以某种方式为拖拽添加一个侦听器,以防止将拖拽带到外部的移动。我只能在
对话框中看到onMouseMove
,beginDragging
,endDragging
方法,我建议尝试gwtquery dnd。我一直在使用拖放插件,效果非常好。它有一个选项setContianment(Element elem),这是您正在寻找的。其他一些特性是,它有snap,所以如果您希望将对话框停靠在某个位置,可以捕捉到其他小部件。它还可以指定一个类似于对话框标题的句柄进行拖动
我建议试试gwtquery dnd。我一直在使用拖放插件,效果非常好。它有一个选项setContianment(Element elem),这是您正在寻找的。其他一些特性是,它有snap,所以如果您希望将对话框停靠在某个位置,可以捕捉到其他小部件。它还可以指定一个类似于对话框标题的句柄进行拖动
您可以调查com.google.gwt.user.client.ui.DialogBox源代码,并根据需要覆盖所有方法。有两种方法负责在那里拖动
我不确定你能用其他方法解决这个问题。否则,您需要开发自定义的可拖动弹出面板,我确信这不是一个好的解决方案。您可以研究com.google.gwt.user.client.ui.DialogBox源代码,并根据需要覆盖所有方法。有两种方法负责在那里拖动
我不确定你能用其他方法解决这个问题。否则,您需要开发自定义可拖动弹出面板,我确信这不是一个好的解决方案。“我们”已通过以下方式解决了此问题:
@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);
}
@覆盖
受保护的void EndDraging(MouseUpEvent事件)
{
int genericMargin=60;
int leftMargin=-(this.getOffsetWidth()-genericMargin);
int lowerMargin=Window.getClientHeight()-genericMargin;
int rightMargin=Window.getClientWidth()-genericMargin;
int上限=0;
if(this.getAbsoluteLeft()>rightMargin)
{this.setPopupPosition(rightMargin,this.getPopupTop());}
if(this.getAbsoluteLeft()lowerMargin)
{this.setPopupPosition(this.getPopupLeft(),lowerMargin);}
if(this.getAbsoluteTop()
顺便说一句,它可以正常工作!;) “我们”通过以下方式解决了这个问题:
@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);
}
@覆盖
受保护的void EndDraging(MouseUpEvent事件)
{
int genericMargin=60;
int leftMargin=-(this.getOffsetWidth()-genericMargin);
int lowerMargin=Window.getClientHeight()-genericMargin;
int rightMargin=Window.getClientWidth()-genericMargin;
int上限=0;
if(this.getAbsoluteLeft()>rightMargin)
{this.setPopupPosition(rightMargin,this.getPopupTop());}
if(this.getAbsoluteLeft()lowerMargin)
{this.setPopupPosition(this.getPopupLeft(),lowerMargin);}
if(this.getAbsoluteTop()
顺便说一句,它可以正常工作!;)