File Exchange

image thumbnail

enable/disable entire figure window

version 1.5.0.0 (6.86 KB) by Yair Altman
enable/disable entire figure window, including toolbar, menubar, frame and all contents

4 Downloads

Updated 11 Dec 2016

View License

Syntax:
currentState = enableDisableFig(hFig, newState)

Description:
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'.

Examples:
state = enableDisableFig;
state = enableDisableFig(hFig);
oldState = enableDisableFig(hFig, 'on');
oldState = enableDisableFig(hFig, result>0);
oldState = enableDisableFig(true); % on current figure

Technical description:
http://UndocumentedMatlab.com/blog/disable-entire-figure-window

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

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

Comments and Ratings (19)

Yair Altman

The cursor is fixed to the default cursor (arrow) when the entire figure window is disabled - this is a system feature that cannot be changed programmatically AFAIK.

Thanks, this is indeed very handy. It'd be great if you can fix the issue Adam mentioned below. I was also trying to do something similar and observed this bug.

Adam

Adam (view profile)

Unfortunately this seems to reset the figure pointer to the arrow, which is a problem common to other options I have tried to disable interaction with a UI. It does exactly what I want apart from that, but if I have to choose I'd rather my users see a busy cursor and trust them not to click the UI when it is shown than freeze the UI with no indication that something is happening.

Yair Altman

@Kris - the new version of this utility should fix this problem

Kris Janssen

I recently tried to run this on Matlab 2016b on Mac.

I noticed an error occurring:

set(jff,'Enabled',newState);

only works If newState is scalar (so 0 or 1). Trying to set it with 'on' or 'off' or true/false doesn't work at all.

Perhaps this is a change in 2016b? In any case, setting 0 or 1 makes the code work again.

Timo Dörsam

Yair Altman

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

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

Claudio

Igor

Igor (view profile)

@Yair Altman
Thanks, it works!

Yair Altman

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

Igor

Igor (view profile)

Uh-Oh...
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?

Igor

Igor (view profile)

Thanks! Exactly what i was looking for!

Excellent as always Yair.
Some users might like to complement this with altering figure opacity for a disabled figure. My own MUtilities support that
e.g.
>>MUtilities.setFigureOpacity(hFig,.5);
http://www.mathworks.com/matlabcentral/fileexchange/28326-mutilities

Cem

Cem (view profile)

Yair,
Thank you. It worked like a charm.

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!

norm thing

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

Updates

1.5.0.0

Fix for 'on'/'off' on new Matlab releases

1.4.0.0

Fix for HG2 (R2014+)

1.3.0.0

Fix for R2011b; fixed description

1.2.0.0

Removed warning messages that appeared in modern Matlab releases

MATLAB Release Compatibility
Created with R2007a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor