GUI Examples #12:Explore string color control

January 4, 2010 by Matt Fig 
Filed under: GUI, Tutorials 
Leave a Comment
VN:F [1.8.8_1072]
Rating: 0 (from 0 votes)
VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)

A listbox with strings of different colors is presented.  Pushing the pushbutton prints the user’s choice to the command window.

GUIExample12

function [] = GUI_12()
% Demonstrate colored text in a listbox, & how extract user's choice.  
% Creates a listbox which has words of different colors.  When the
% pushbutton is pushed, the users choice is printed to the screen.
% Notice the use of the 'listboxtop' property in the callback.
% This does NOT work in version 6.5.
%
% Author:  Matt Fig
% Date:  7/15/2009
 
S.fh = figure('units','pixels',...
 'position',[300 300 230 40],...
 'menubar','none',...
 'name','GUI_12',...
 'numbertitle','off',...
 'resize','off');
% We will get different colors by using HTML.   
STR = {'<HTML><FONT COLOR="#66FF66">Green</FONT></HTML>',...
 '<HTML><FONT COLOR="red">Red</FONT></HTML>',...
 '<HTML><FONT COLOR="blue">Blue</FONT></HTML>',...
 '<HTML><FONT COLOR="#FF00FF">Violet</FONT></HTML>',...
 '<HTML><FONT COLOR="black">Black</FONT></HTML>',...
 '<HTML><FONT COLOR="yellow">Yellow</FONT></HTML>'};
S.COL = {'Green','Red','Blue','Violet','Black','Yellow'}; % Lookup table.
S.ls = uicontrol('style','list',...
 'units','pix',...
 'position',[10 10 90 25],...
 'string', STR,...
 'fontsize',14);
S.pb = uicontrol('style','push',...
 'units','pix',...
 'posit',[120 10 100 25],...
 'string', 'Print Choice',...
 'fontsize',10,...
 'callback',{@pb_call,S}); 
 
function [] = pb_call(varargin)
% Callback for pushbutton.  Displays user's choice at command line.
S = varargin{3}% Get structure.
% If the 'value' property was used below, the user's choice might not show
% correctly if the selection was made with the arrows on the listbox.
L = get(S.ls,'listboxtop'); % Get the user's choice.
disp(['Your color choice is:  ' S.COL{L}]) % Print to command line.
VN:F [1.8.8_1072]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.8_1072]
Rating: 0 (from 0 votes)

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

Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


Include MATLAB code in your comment by doing the following:

<pre lang="MATLAB">

%insert code here

</pre>