Tip: How to detect that a View was Detached
Here is a question that I got on a post about detached views:
“How can I detect that a View has been detached from the main window? I would like to adjust the view’s behavior in that case.”
There is no API to obtain that information directly. However it is possible to do this with a few tricks:
- detached views have an empty window title (i.e. shell.getText().length() == 0)
- when a view is detached resize events are fired
Armed with that knowledge we can detect that a view is detached / reattached. The snippet below shows how (tested on windows).
PS: Our eclipse support helps developers use their time efficiently by providing prompt answers to questions like this one.
![](/blogs/2010/06/23/tip-how-to-detect-that-a-view-was-detached/images/detached_view_huac3ca4f54d338ce14d2d77bb7da35bbd_36162_560x417_resize_q100_h2_box_3.webp)