GUI Examples #3: Explore visibility properties.

October 18, 2009 by Matt Fig 
Filed under: GUI, Tutorials 
Leave a Comment
VN:F [1.8.8_1072]
Rating: +1 (from 1 vote)
VN:F [1.8.8_1072]
Rating: 10.0/10 (1 vote cast)

A uicontrol element is set to be visible and invisible by a checkbox.

GUIExample3

function [] = GUI_3()
% Demonstrate how to hide a uicontrol from the user.  
% Creates a textbox and a checkbox.  The state of the checkbox determines
% whether or not the textbox is visible.
%
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 200 130],...
 'menubar','none',...
 'name','GUI_3',...
 'numbertitle','off',...
 'resize','off');        
S.tx = uicontrol('style','text',...
 'unit','pix',...
 'position',[10 70 180 40],...
 'string','Hello',...
 'backgroundcolor','r',...
 'fontsize',23);
S.ch = uicontrol('style','check',...
 'unit','pix',...
 'position',[10 20 180 35],...
 'string','   Check2hide',...
 'fontsize',14);
set(S.ch,'callback',{@ch_call,S})  % Set callback.
 
function [] = ch_call(varargin)
% Callback for pushbutton.
S = varargin{3}% Get the structure.
 
switch get(S.tx,'visible')
 case 'on'     % The text is visible, make it invisible.
 set(S.ch,'string','   Uncheck2show');
 set(S.tx,'visible','off')
 case 'off'    % The text is invisible, make it visible.
 set(S.ch,'string','   Check2hide');
 set(S.tx,'visible','on')
 otherwise  % This should never happen!
 disp('Matlab entered the twilight zone, aborting.')
 close(gcbf)
 quit
end

Download full list of examples

VN:F [1.8.8_1072]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.8_1072]
Rating: +1 (from 1 vote)
GUI Examples #3: Explore visibility properties.10.0101

Popularity: 1% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

Related Posts

Comments

Comments are closed.