- Undocumented Matlab - https://undocumentedmatlab.com -

Docking figures in compiled applications

Posted By Yair Altman On June 15, 2011 | 30 Comments

Up until Matlab release R2008a, the Matlab compiler enabled compiled Matlab applications to have dockable figure windows, which docked into a “Figures” container. Starting with R2008a [1], the compiler removed the figure’s docking capability and figures can no longer be docked.
Well, at least not officially 🙂
The following trick restores the docking controls to figures in R2008a-compiled applications, enabling figure docking. Simply add one or both of the following alternatives in your application, after the figure has been created:

% Alternative #1 - uses pure Matlab
set(hFig, 'DockControls', 'on');
% Alternative #2 - uses the underlying Java frame
jFrame = get(handle(hFig), 'JavaFrame');
   % This works up to R2011a
   % This works from R2008b and up

where hFig is the figure handle. This will have no effect for the regular interpreted (non-compiled) run of the application, where these controls are ‘on’ by default. But in the compiled application, although it may erroneously report that the controls are ‘on’, they are in fact ‘off’, so turning them ‘on’ fixes the problem.

Matlab figure docking control
Matlab figure docking control

Note: the two variants in alternative #2 above are actually identical, it is simply that the relevant field name has changed: Up to R2008a, only the fFigureClient existed; in R2008b, the fHG1Client field was added, which was simply an alias for fFigureClient, holding the same reference handle, so either of these fields could be used (a corresponding fHG2Client was also added – more on HG1 and HG2 here [2]). In R2011b (at least the pre-release), the fFigureClient alias field was dropped and only fHG1Client remained. While the field name has changed, the underlying docking functionality appears to have remained stable over all these releases. For the record, in answer to a user question below [3], these fields can be listed using the built in fieldnames function:

% R2008b - R2011a:
>> fieldnames(jFrame)
ans =

I was reminded of this trick by Aurélien’s recent comment [4], where he mentions MathWorks so-called workaround for this problem, which (IMHO) is really not a work-around at all: MathWorks advises to modify our application to use – would you believe this – tabbed panels to “dock” the separate figures contents onto separate panels. Not to mention the fact that this so-called “solution” relies on undocumented and unsupported Matlab functionality (that of tabbed-panels [5]) and requires major rework of existing applications, it also results in far inferior look-and-feel than simple docking as G-d intended…
Since I have demonstrated above that the docking functionality actually exists in compiled apps just as in the interpreted m-file apps, I do not understand why MathWorks took such great pains to prevent this important functionality in the compiler. There must be some important reason for this, but I cannot think of any. Perhaps if there is enough public demand, MathWorks will agree to return the docking functionality.
Unfortunately, I recently discovered that in the most recent compiler, that ships with R2011a, alternative #1 above (which uses pure Matlab) no longer works. Sometime between R2008a and R2011a MathWorks discovered my first back-door and closed it. Such a pity…
Luckily, alternative #2 (which uses the underlying Java frame object) seems to still work, even on R2011a.
I still haven’t tested this on R2011b’s compiler (whose pre-release has become available for download yesterday), but hopefully the trick above will continue to work on R2011b and on subsequent releases – please tell me [6] if you find out otherwise.
Addendum: Since 2013, possibly as a direct result of this post, MathWorks have prevented this workaround. MathWorks officially states [7] that docking figures is not possible in deployed applications. I do not know the reason for this, and I have still not discovered if another workaround for this annoying limitation is possible.

Categories: Figure window, High risk of breaking in future versions, Java, Undocumented feature

30 Comments (Open | Close)

30 Comments To "Docking figures in compiled applications"

#1 Comment By Mikhail On June 16, 2011 @ 10:19

You are as always great, Yair! Question: what about docked figure OnCreate/OnDelete callbacks?

#2 Comment By Marco H. On June 17, 2011 @ 00:51

Thanks a lot for this Information. I tested the 2 solutions with 2010a and 2011b. In 2010a Alternative #2 is working and in 2011b none of them is working…


#3 Comment By Yair Altman On June 19, 2011 @ 02:55

@Marco – in R2011b, the relevant field name has changed. I’ve updated the article text accordingly.

#4 Comment By Manish On June 17, 2011 @ 07:23

Hi guys,

M Manish from Indian Institute Of technology- Madras, doing my masters in transportation engineering and carrying out the research in the Advanced Traveler Information Systems(ATIS), as a part of the research for the ATIS project, v r using the neural network tool box in the mat-lab for the mapping purpose. The input for this mapping is basically either o or 1 which we will be getting by the other software on image-processing. The basic function of the mapping is to reduce the noise in the output obtained from the image-processing software and to classify it into different categories based on the density obtained from the field through the image-processing software. In order to classify the matlab into different categories we need to carryout the optimization based on the time(i.e input 1 or 0 depending on the time the vehicle is occupied the portion in the video). So i request you to post the code’s of ANN tool box in the matlab which helps me in attaining the above said objective of classification into different levels

#5 Comment By Yair Altman On June 17, 2011 @ 07:59

I’m sorry but I cannot help you – the Matlab software is copyrighted and I will not post it. If you want the NN toolbox, purchase a license from MathWorks.

#6 Comment By Manish On June 18, 2011 @ 00:52

Dear Yair,

I already have the licensed version of the Matlab and also the ANN tool box too. I just need help in the coding part as M not basically a electronics or CS or Electrical to know all the codes. I’m not able to figure out how to perform the mapping. So i just asked your help so that you will help me in coding the mapping i require for my project. I hope you help me in that part.

#7 Comment By Yair Altman On June 19, 2011 @ 02:43

Dear Manish – I’m always willing to do consulting work for clients. This is [14]. If you are interested, please [15] so that we can discuss your needs and my fee.

#8 Comment By Paul Andrews On June 18, 2011 @ 05:38


I am unabled to get alternative #1 or #2 to work in R2011b.
R2011b issues the following error when setting the attempting to set the ClientDockable property.

>> jframe.fFigureClient.setClientDockable(true)
No appropriate method, property, or field fFigureClient for class com.mathworks.hg.peer.HG1FigurePeer.

By the way, is fFIgureClient a hidden methods or property? I cannot see it using get(jframe) nor using methodsview(jframe) (even in R2008b where this line executes without errors or issues)
Any thoughts?

#9 Comment By Yair Altman On June 19, 2011 @ 02:22

@Paul, Marco – in R2011b, the relevant field name has changed. I’ve updated the article text accordingly. They are actually neither properties nor methods, but rather public fields of the jFrame object that can be seen via the fieldnames function.

#10 Comment By Paul Andrews On June 19, 2011 @ 14:45


Thank you for your answer.
Using fHG1Client instead of fFigureClient solves the “No appropriate method, property, or field …” error in R2011b. However, the root issue persists. I have not been able to get the dock controls to show up once compiled.

I’ve tested both alternatives in R2011a (Mac OS X) and R2011b (Win7 32bits), and neither one worked.

Have you had success doing so? If so, which version are know to work?

Marco – what about you? Have you been able to get a compiled figure with dock controls in R2011a or b?


#11 Comment By Yair Altman On June 19, 2011 @ 15:05

@Paul – it worked for me on R2011a Win XP. As I said in the post, I haven’t tested R2011b.

#12 Comment By Paul Andrews On June 20, 2011 @ 05:22

Thank you Yair. I’ll try R2011a and make sure I am not doing anything silly.
Please update your post once you test R2011b and let us know if you get it to work.
Thank you in advance.


#13 Comment By Paul Andrews On June 20, 2011 @ 11:31


I discovered that I can get R2011b by adding a small pause between getting the jFrame and setting the setClientDockable.
See below.

% Alternative #1 - uses pure Matlab
set(hFigure, 'DockControls', 'on');

% Alternative #2 - uses the underlying Java frame
jFrame = get(handle(hFigure), 'JavaFrame');
pause(0.1);  % This pause is needed, otherwise, the dock controls will not get enabled
   % This works up to R2011a
catch ME
   % This works from R2008b and up

I am not sure why the pause is needed. I suspected a dispatching timing issue, but using javaMethodEDT for the setClientDockable did not help. Perhaps the jFrame variable is not ready when the method is called.


#14 Comment By Frank On July 20, 2011 @ 07:34

Thank you Paul for your tip!
I needed this small pause, too. I’m using Matlab R2010b…


#15 Comment By sb On July 28, 2011 @ 16:04

To dock programmatically:

function DockFig(hFig,Docked)
     if length(hFig)>1 %if it is an array of figs....
         arrayfun(@(h) DockFig(h,Docked), hFig);
     end %if
     jFrame = get(handle(hFig), 'JavaFrame');
     pause(0.1);  % This pause is needed, otherwise, the dock controls will not get enabled
         % This works up to R2011a
         % This works from R2008b and up
end  %DockFig  

#16 Comment By Jeremy On August 1, 2012 @ 06:30

OK – so now I have this awesome ability to dock re-enabled… (THANK YOU! Man, I hated loosing that feature). Do you know any way to address the “Figures” frame so I can change the name on it?

#17 Comment By Yair Altman On August 1, 2012 @ 06:49

@Jeremy – of course: take a look at my [16].

#18 Comment By Jeremy On August 1, 2012 @ 07:42

Awesome! Thanks as always (and let me put a plug in for your book… that has been a great purchase!)

#19 Pingback By Disabling menu entries in deployed docked figures | Undocumented Matlab On November 15, 2012 @ 16:34

[…] One of these very useful hints is the ability to dock figure windows in standalone applications. This perfectly fits to my understanding of a clean desktop […]

#20 Pingback By HG2 update | Undocumented Matlab On May 16, 2013 @ 07:26

[…] In order to access the top-level Java Frame of a figure window, we now need to use javaFrame.fHG2Client rather than javaFrame.fHG1Client […]

#21 Comment By Matt On April 1, 2014 @ 05:47

First of all, your website is great. Are there commands to control the size of a docked figure? For example, if I have two figures in a container, are there any commands to make one figure span 1/4 of the width of the container and another to span the final 3/4?

#22 Comment By Yair Altman On April 1, 2014 @ 05:50

@Matt – I’m sure that there are ways to do this, but I’ve never investigated this.

#23 Comment By Legion On March 5, 2015 @ 14:38


Great site. Thanks. Looks like no alternatives work as of 2012a. I’ve tried 2012a and 2014b. Any other workarounds or things that I could research?

#24 Comment By amir On January 7, 2016 @ 16:58

why matworks donot need matlab gui is beter??
because matwork remove docked figure in compiled apps from matlab2008

docked figure make gui very beautifull

#25 Comment By Arwel Hughes On March 21, 2016 @ 16:58

Hi Yair,
What is the equivalent for this in R2015? There does seem to be a ‘jFrame.fHG2Client’, but it doesn’t seem to behave the same…

#26 Comment By Yair Altman On March 23, 2016 @ 09:46

@Arwel – see [17]

#27 Comment By Ravi On May 12, 2016 @ 18:32

Hi Yair,
Thanks for such a nice document.
but unfortunately, none of these work for me in 2013b.
I badly need docked feature in compiled application. Is there a way I can achieve it?

#28 Comment By Michael Livshitz On January 24, 2018 @ 01:15

Hi Yair,
Lots of useful information here, thanks!
I also want to enable docking feature for deployed application.
I used R2015/2016/2017. I tried native Matlab, jFrames, pause(), HG2 compiler flags – nothing seemed to work: once complied, I am getting default figures.
Do you know of any successful solution for recent Matlab versions?

#29 Comment By Christian D On December 11, 2018 @ 18:31

Hi Michael!
Same problem here! Have you already been able to fix the problem by now? I would be glad if you could tell me the solution then.

#30 Comment By Paul Andrews On September 21, 2018 @ 22:09

I am also having problems docking figures in a compiled application using the newer releases (R2016a and up). I’ve tried all of the suggestions above, but none of them worked. If somebody has a solution, please post it.
Thanks in advance,


Article printed from Undocumented Matlab: https://undocumentedmatlab.com

URL to article: https://undocumentedmatlab.com/articles/docking-figures-in-compiled-applications

URLs in this post:

[1] Starting with R2008a: http://www.mathworks.com/support/solutions/en/data/1-A6XFET/

[2] here: http://undocumentedmatlab.com/blog/tag/hg2/

[3] user question below: http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#comment-48632

[4] Aurélien’s recent comment: http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/#comment-47197

[5] tabbed-panels: http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/

[6] tell me: http://undocumentedmatlab.com/blog/docking-figures-in-compiled-applications/#respond

[7] officially states: https://www.mathworks.com/matlabcentral/answers/378640-compiled-application-can-t-dock-figures

[8] Disabling menu entries in deployed docked figures : https://undocumentedmatlab.com/articles/disabling-menu-entries-in-deployed-docked-figures

[9] Matlab toolstrip – part 9 (popup figures) : https://undocumentedmatlab.com/articles/matlab-toolstrip-part-9-popup-figures

[10] Speeding up compiled apps startup : https://undocumentedmatlab.com/articles/speeding-up-compiled-apps-startup

[11] Quirks with compiled Matlab DLLs : https://undocumentedmatlab.com/articles/quirks-with-compiled-matlab-dlls

[12] Splash window for deployed applications : https://undocumentedmatlab.com/articles/splash-window-for-deployed-applications

[13] JGraph in Matlab figures : https://undocumentedmatlab.com/articles/jgraph-in-matlab-figures

[14] : https://undocumentedmatlab.com/consulting/

[15] : mailto:%20altmany%20@gmail.com?subject=Matlab%20consulting&body=Hi%20Yair,%20&cc=&bcc=

[16] : http://www.mathworks.com/matlabcentral/fileexchange/16650-setfigdockgroup

[17] : https://undocumentedmatlab.com/blog/hg2-update#observations

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.