Display different Color in a popup menu using GUIDE

3 views (last 30 days)
Hi there,
I’m trying to create a popup menu for Color Selection. I managed to display the different Colors in the popup menu (see first picture) ...
but since one is selected it doesn’t display the Color anymore. Instead it shows the HTML Code that I am using to display the Color (second picture)
Can someone please help displaying the selected Color? Tanks a lot!
My Code is the following:
%HTML text to display Colors
colergen = @(color,text) ['<html><table border=0 width=50 bgcolor=',color,'><TR><TD>',text,'</TD></TR> </table></html>'];
set(handles.uitable1, 'columnname', {'Region', 'visible', 'Color'});
set(handles.uitable1, 'columneditable', [true,true,true])
col_fmt = get(handles.uitable1, 'ColumnFormat');
col_fmt{3} = {colergen('#353477', ' '), colergen('#EBF4FC', ' '), colergen('#FFF7E7', ' ')}
set(handles.uitable1, 'ColumnFormat', col_fmt);
set(handles.uitable1, 'columneditable', [true,true,true])
Names = {'Region 01', true, ''; 'Region 02', true, ''};
set(handles.uitable1, 'data', Names);
  3 Comments
Lisann Lieb
Lisann Lieb on 26 Apr 2018
Thanks Walter, I decided to devide the Color column in two columns. So I have one for the popup menu which is so small, that only the dropdown arrow is visible. And one to display the selected Color.
Unfortunatly I have problems getting the selected "value" of the popup menu. Since this is a cell ... Can you explain how to do this?
Thanks a lot!
Walter Roberson
Walter Roberson on 26 Apr 2018
For columns defined to be pop-up menus, the value at each cell location in that row is the index of the selected entry.
data = get(handles.uitable1, 'data');
mask = cellfun(@isempty, data(:,3));
data(mask,3) = {0};
selections = cell2mat(data(:,3));
I do not know at the moment whether it is possible for there to be empty selections so I decided it would be safer to put that code in.

Sign in to comment.

Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!