MATLAB set background color in a cell of uicontrol

牧云@^-^@ 提交于 2019-12-24 17:02:17

问题


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

something like:

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?


回答1:


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


来源:https://stackoverflow.com/questions/12918923/matlab-set-background-color-in-a-cell-of-uicontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!