Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

Docking figures in compiled applications

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, 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

% 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.

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 =
    'fFigureClient'
    'fHG2Client'
    'fHG1Client'
    'fUseHG2'
    'UICONTROLBACKGROUND_OS'
    'UICONTROLBACKGROUND_COMPATIBLE'

% 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.

Related posts:

  1. Disabling menu entries in deployed docked figures – Matlab's standard menu items can and should be removed from deployed docked figures. This article explains how. ...
  2. Matlab toolstrip – part 9 (popup figures) – Custom popup figures can be attached to Matlab GUI toolstrip controls. ...
  3. Speeding up compiled apps startup – The MCR_CACHE_ROOT environment variable can reportedly help to speed-up deployed Matlab executables....
  4. Quirks with compiled Matlab DLLs – Several quirks with Matlab-compiled DLLs are discussed and workarounds suggested. ...
  5. Splash window for deployed applications – Deployed (compiled) Matlab applications take a long time to load. I present a splash window that loads immadiately, solving this problem. ...
  6. JGraph in Matlab figures – JGraph is a powerful open-source Java library that can easily be integrated in Matlab figures. ...
Compiler Docking Figure Java JavaFrame Pure Matlab Undocumented feature
Print Print
« Previous
Next »
30 Responses
  1. Mikhail June 16, 2011 at 10:19 Reply

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

  2. Marco H. June 17, 2011 at 00:51 Reply

    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

    • Yair Altman June 19, 2011 at 02:55 Reply

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

  3. Manish June 17, 2011 at 07:23 Reply

    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

    • Yair Altman June 17, 2011 at 07:59 Reply

      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 June 18, 2011 at 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.

      • Yair Altman June 19, 2011 at 02:43

        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 June 18, 2011 at 05:38 Reply

    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.

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

    >> 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?

    • Yair Altman June 19, 2011 at 02:22 Reply

      @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 June 19, 2011 at 14:45 Reply

    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

    • Yair Altman June 19, 2011 at 15:05 Reply

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

  6. Paul Andrews June 20, 2011 at 05:22 Reply

    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

  7. Paul Andrews June 20, 2011 at 11:31 Reply

    Yair,

    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
    try
       % This works up to R2011a
       jFrame.fFigureClient.setClientDockable(true);
    catch ME
       % This works from R2008b and up
       jFrame.fHG1Client.setClientDockable(true);
    end

    % 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 try % This works up to R2011a jFrame.fFigureClient.setClientDockable(true); catch ME % This works from R2008b and up jFrame.fHG1Client.setClientDockable(true); end

    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

    • Frank July 20, 2011 at 07:34 Reply

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

      Frank

  8. sb July 28, 2011 at 16:04 Reply

    To dock programmatically:

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

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

  9. Jeremy August 1, 2012 at 06:30 Reply

    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?

    • Yair Altman August 1, 2012 at 06:49 Reply

      @Jeremy – of course: take a look at my setFigDocGroup utility.

    • Jeremy August 1, 2012 at 07:42 Reply

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

  10. Disabling menu entries in deployed docked figures | Undocumented Matlab November 15, 2012 at 16:34 Reply

    […] 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 […]

  11. HG2 update | Undocumented Matlab May 16, 2013 at 07:26 Reply

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

  12. Matt April 1, 2014 at 05:47 Reply

    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?

    • Yair Altman April 1, 2014 at 05:50 Reply

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

  13. Legion March 5, 2015 at 14:38 Reply

    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?

  14. amir January 7, 2016 at 16:58 Reply

    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 March 21, 2016 at 16:58 Reply

    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

    • Yair Altman March 23, 2016 at 09:46 Reply

      @Arwel – see http://undocumentedmatlab.com/blog/hg2-update#observations

  16. Ravi May 12, 2016 at 18:32 Reply

    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?

  17. Michael Livshitz January 24, 2018 at 01:15 Reply

    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

    • Christian D December 11, 2018 at 18:31 Reply

      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

  18. Paul Andrews September 21, 2018 at 22:09 Reply

    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

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab Β© 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top