Docking figures in compiled applications

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 :-)

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). 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 = 

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.

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

Tags: , , , , , ,

Bookmark and SharePrint Print

27 Responses to Docking figures in compiled applications

  1. Mikhail says:

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

  2. Marco H. says:

    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. Manish says:

    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.

    • Manish says:

      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.

  4. Paul Andrews says:


    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?

    • @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.

  5. Paul Andrews says:


    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?


  6. Paul Andrews says:

    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.


  7. Paul Andrews says:


    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.


    • Frank says:

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


  8. sb says:

    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
  9. Jeremy says:

    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?

  10. Pingback: Disabling menu entries in deployed docked figures | Undocumented Matlab

  11. Pingback: HG2 update | Undocumented Matlab

  12. Matt says:

    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?

  13. Legion says:


    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?

  14. amir says:

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

    docked figure make gui very beautifull

  15. Arwel Hughes says:

    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…

  16. Ravi says:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *