Search code examples
matlabcelluicontrol

MATLAB set background color in a cell of uicontrol


I want to set a background color in a cell..

something like:

enter image description here

so I have the RGB color and the number of cell I want to color.

you can assume that the position of the cell is what I wrote.

my color is given by RGB:

color = [255 0 0];

I want to add it in the 10th cell, so I wrote something like:

S.cell_data(10) = uicontrol('style','text',...
               'units','pix',...
               'Position',[20 70 80 40],...
               'string',color);

but the style is not 'text' and it is no a string.

this is what I'm trying right now:

S.cell_data(10) = uicontrol('style','text',...
               'units','pix',...
               'Position',[125 70 80 40],...
               'string','fh');

parentColor = get(get(S.cell_data(10), 'parent'), 'color');

set(S.cell_data(num_of_cols+1),'foregroundcolor', [0 0 0], ...
  'backgroundcolor', parentColor);

somebody knows?


Solution

  • blue = 255;
    green = 0;
    red = 0;
    
    rgb_str = strcat('<HTML><BODY bgcolor = "rgb(', num2str(red), ', ', num2str(green), ', ', num2str(blue), ')">green background</BODY></HTML>');
    
    S.cell_data(10) = uicontrol('Style','pushbutton', 'Position',[20 70 80 40], 'String', {rgb_str});