View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
enable/disable entire figure window

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

4.7 | 8 ratings Rate this file 9 Downloads (last 30 days) File Size: 6.69 KB File ID: #15895 Version: 1.4

enable/disable entire figure window


Yair Altman (view profile)


10 Aug 2007 (Updated )

enable/disable entire figure window, including toolbar, menubar, frame and all contents

| Watch this File

File Information

  currentState = enableDisableFig(hFig, newState)
enableDisableFig sets the figure hFig's enable/disable state, which is otherwise supported by Matlab only for specific components but not figures. Using this function, the entire figure window, including all internal menus, toolbars and components, is enabled/disabled in a single call. Valid values for newState are true, false, 'on' & 'off' (case insensitive). hFig may be a list of figure handles.
Note 1: when the state is enabled, internal figure components may remain disabled if their personal 'enabled' property is 'off'.
Note 2: in disabled state, a figure cannot be moved, resized, closed or accessed. None of its menues, toolbars, buttons etc. are clickable.
enableDisableFig(newState) sets the state of the current figure (gcf).
state = enableDisableFig(hFig) returns the current enabled/disabled state of figure hFig, or of the current figure (gcf) if hFig is not supplied. The returned state is either 'on' or 'off'.
  state = enableDisableFig;
  state = enableDisableFig(hFig);
  oldState = enableDisableFig(hFig, 'on');
  oldState = enableDisableFig(hFig, result>0);
  oldState = enableDisableFig(true); % on current figure

Technical description:

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!


Findjobj Find Java Handles Of Matlab Graphic Objects and Get J Frame Retrieves A Figure's Underlying Java Frame inspired this file.

This file inspired Set Fig Transparency Set Figure Transparency / Fading, Blur Figure Blurs And Prevents Interaction On A Figure Window, Undecorate Fig Remove/Restore Figure Border And Title Bar, and Laser Speckle Analysis Software.

MATLAB release MATLAB 7.4 (R2007a)
MATLAB Search Path
Other requirements Java
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
05 Dec 2014 Timo Dörsam  
21 Mar 2012 Yair Altman

Yair Altman (view profile)

@Claudio - if the figure is not yet visible, then its Java Frame cannot be retrieved and this utility will therefore fail to work.

Comment only
02 Jan 2012 Claudio

It fails on my machine: Mac OSX Lion 10.7.2 with R2011b. The error is:

Error using enableDisableFig>getJFrame (line 181)
Cannot retrieve figure's java frame

Error in enableDisableFig>getJFrame (line 181)
error('Cannot retrieve figure''s java frame');

Error in enableDisableFig (line 81)
jff = getJFrame(hFig(figIdx));

02 Jan 2012 Claudio  
17 Oct 2011 Igor

Igor (view profile)

@Yair Altman
Thanks, it works!

Comment only
13 Oct 2011 Yair Altman

Yair Altman (view profile)

@Igor - I uploaded a fix for R2011b. It should be available here shortly (maybe tomorrow)

Comment only
26 Sep 2011 Igor

Igor (view profile)

It fails on R2011b
Error using enableDisableFig>getJFrame (line 173)
Cannot retrieve figure's java frame

Error in enableDisableFig>getJFrame (line 173)
error('Cannot retrieve figure''s java frame');

Error in enableDisableFig (line 77)
jff = getJFrame(hFig(figIdx));
any chance to get it working again?

Comment only
24 Jul 2011 Igor

Igor (view profile)

Thanks! Exactly what i was looking for!

28 Feb 2011 Malcolm Lidierth

Excellent as always Yair.
Some users might like to complement this with altering figure opacity for a disabled figure. My own MUtilities support that

24 Aug 2009 Cem

Cem (view profile)

Thank you. It worked like a charm.

30 Sep 2008 Cat H

Does exactly what it says on the tin! I'm using it to prevent the user being able to create phantom waitbars by pressing the close button.

Many thanks!

21 Jul 2008 norm thing

Thank you for this code! Works wonderfull on 2008a!

18 Feb 2011 1.2

Removed warning messages that appeared in modern Matlab releases

13 Oct 2011 1.3

Fix for R2011b; fixed description

23 Feb 2016 1.4

Fix for HG2 (R2014+)

Contact us