How to prevent GWT DialogBox from being dragged out of the screen?


I am looking for a simple solution for the issue that my GWT DialogBox can be dragged out of the screen. The host has the CSS rule overflow:hidden because I do not want any scrollbars to appear.

Obviously I need to attach somehow a listener to the dragging and prevent moves that would bring it outside. I can only see onMouseMove, beginDragging, endDragging methods in DialogBox.


"We" have worked around this issue in the following way:

@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); }

BTW it correctly works as it is! ;)


I would suggest trying gwtquery-dnd. I have been using the drag and drop plugin and it works great. It has an option to setContianment(Element elem) which is what you are looking for. Some other features is that it has snap so you can snap to other widgets if you wish to dock your dialog box somewhere. It also has the ability to specify a handle similar to the DialogBox header for dragging.

<a href="http://code.google.com/p/gwtquery-plugins/wiki/DragAndDropPluginForGWTDeveloppers" rel="nofollow">http://code.google.com/p/gwtquery-plugins/wiki/DragAndDropPluginForGWTDeveloppers</a>


You can investigate com.google.gwt.user.client.ui.DialogBox source code and override all methods for your need. There are a couple of methods responsible for dragging there.

Not sure you can solve this problem in other ways. Otherwise you need to develop custom draggable popup panel which I am sure not a good solution.


  • Change Text Color, Hyperlink Color, and Image With Javascript [duplicate]
  • Jasper iReport table returns an empty document although query works
  • How to set textfield when the parameter list more than one
  • JasperReports: JRDataSource.subDataSource shows undefined
  • Slide image from left to right and right to left
  • GWT Widget.addHandler
  • Regarding starting the threads on a condition
  • How to access profile picture with Facebook API in Swift 3?
  • How to use jQuery's $.post() method with async/await and typescript
  • Question about instantiating object
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • Angularjs pass function from Controller to Directive (or call controller function from directive) -
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • Checking if an array in C is symmetric
  • c# open webrowser in many tab
  • Bypass multiple inheritance in Java
  • how to find common suffix in java by using method
  • Display java JPanel in a JFrame
  • onBackPressed() not being executed
  • iOS: Detect app start via notification press
  • Alert pop up with LWUIT
  • how to adjust image in a panel in Java swing?
  • How to access EntityManager inside Entity class in EJB3
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • how to do an event when i swipe from fragment to the other
  • JFileChooser in front of fullscreen Swing application
  • HTML download movie download link
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • Possible to stop flickering java tooltip in heavyweight mode?
  • sending/ receiving email in Java
  • Eraser for UIBezierPath
  • AngularJs get employee from factory
  • Suggestions to manage Login/Logout transitions
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?