on Jun 23rd, 2010Tip: 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.

Related posts:
- Having fun with detached views!
- Git Lesson: Be mindful of a detached head
- Introduction to Eclipse Riena UI and Navigation
- Eclipse Riena 1.2.0.M1 released



It’s a bit of hack, thanks a lot.
Do you know the reasons why the API does not exist ? OS constraints ?
Thx for this tip! Could come in handy!
By the way, I’d like to know if and how you can detach a view part programatically! Thx in advance
You are the best, I don’t words.
Thank man, Gad exist for you.
@Jens Kreidler
To detach a view part programatically you need to use internal APIs.
Look at sample project (https://bugs.eclipse.org/bugs/attachment.cgi?id=133197) from https://bugs.eclipse.org/bugs/show_bug.cgi?id=270212. From the View class, you will find an helping mehod (openDetachedView).
I want to resize a RCP view when I resize the window that contains this RCP view.
Does anyone has ideas?
Thank you Mickael!
Hi Elias,
Thank for your answer.
Now, I want to share with you this problem, my app show
Exception in thread “AWT-EventQueue-0″ java.lang.StackOverflowError
at sun.awt.X11.XlibWrapper.CallErrorHandler(Native Method)
at sun.awt.X11.XToolkit.SAVED_ERROR_HANDLER(XToolkit.java:125)
at sun.awt.X11.XToolkit.GlobalErrorHandler(XToolkit.java:136)
when I attach and detach the views. This is the main code.
public void createPartControl(Composite parent) {
this.parent_ = parent;
parent.addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
updateDetached();
}
});
updateDetached();
composite_ = new Composite( parent, SWT.EMBEDDED );
display_ = parent.getDisplay();
display_.asyncExec(new Runnable() {
public void run() {
frame_ = SWT_AWT.new_Frame( composite_ );
}
});
}
I hope to find the solution, it is very important for my project.
Regards,
AEHP