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, the compiler removed the figure’s docking capability and figures can no longer be docked.
Well, at least not officially π
Note: If you are using Matlab R2013a or newer, the workarounds below will not work. Fortunately, I discovered a solution for this annoying limitation that I will NOT publish here – email me ( altmany at gmail) if you need this.
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'); try % This works up to R2011a jFrame.fFigureClient.setClientDockable(true); catch % This works from R2008b and up jFrame.fHG1Client.setClientDockable(true); end |
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.
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). 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, these fields can be listed using the built in fieldnames function:
% R2008b - R2011a: >> fieldnames(jFrame) ans = 'fFigureClient' 'fHG2Client' 'fHG1Client' 'fUseHG2' 'UICONTROLBACKGROUND_OS' 'UICONTROLBACKGROUND_COMPATIBLE' |
I was reminded of this trick by AurΓ©lien’s recent comment, 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) 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 if you find out otherwise.
Addendum: Since 2013, possibly as a direct result of this post, MathWorks have prevented this workaround. MathWorks officially states that docking figures is not possible in deployed applications.
Fortunately, I discovered a solution for this annoying limitation that I will NOT publish here – email me ( altmany at gmail) if you need this.
You are as always great, Yair! Question: what about docked figure OnCreate/OnDelete callbacks?
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…
greetings
@Marco β in R2011b, the relevant field name has changed. Iβve updated the article text accordingly.
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
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.
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.
Dear Manish – I’m always willing to do consulting work for clients. This is my work. If you are interested, please contact me by email so that we can discuss your needs and my fee.
Yair,
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.
By the way, is fFIgureClient a hidden methods or property? I cannot see it using
get(jframe)
nor usingmethodsview(jframe)
(even in R2008b where this line executes without errors or issues)Any thoughts?
@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.
Yair,
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?
Paul
@Paul – it worked for me on R2011a Win XP. As I said in the post, I haven’t tested R2011b.
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.
Paul
Yair,
I discovered that I can get R2011b by adding a small pause between getting the jFrame and setting the
setClientDockable
.See below.
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.Paul
Thank you Paul for your tip!
I needed this small pause, too. I’m using Matlab R2010b…
Frank
To dock programmatically:
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?
@Jeremy – of course: take a look at my setFigDocGroup utility.
Awesome! Thanks as always (and let me put a plug in for your book… that has been a great purchase!)
[…] 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 […]
[…] In order to access the top-level Java Frame of a figure window, we now need to use javaFrame.fHG2Client rather than javaFrame.fHG1Client […]
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?
@Matt – I’m sure that there are ways to do this, but I’ve never investigated this.
Yair,
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?
why matworks donot need matlab gui is beter??
because matwork remove docked figure in compiled apps from matlab2008
docked figure make gui very beautifull
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…
Cheers,
arwel
@Arwel – see http://undocumentedmatlab.com/blog/hg2-update#observations
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?
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?
Thanks,
Michael
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.
Thanks,
Christian
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,
Paul