How to change the color of uitable 'row-wise'?

조회 수: 53 (최근 30일)
Himanshu Verma
Himanshu Verma 2020년 5월 15일
답변: Himanshu Verma 2020년 8월 26일
I have a tool which plots data based on the user selection. The tool plots the line on 3 graphs and I've created uitable which displays the properties of the plotted line. I want to update the color of the text of the row according to the color of the line plotted. The table should get updated whenever a new line is plotted as well as the color of that one row only should change. How can I do that?
function tab_input(ui_table,cell_1a,cell_1b,cell_2,cell_3)
cell_1 = strcat(cell_1a,cell_1b,cell_1a);
existingData = get(ui_table,'Data');
tempData = {cell_1,cell_2,cell_3};
newData = [existingData;tempData];
set(ui_table,'Data',newData,'ForegroundColor',ci_color(cell_2));
end
In the above code, I want to append the table as well as, I want to change the textcolor of the current row only, whereas the color or the previous row (if any) should remain unaltered. Please suggest a workaround.

채택된 답변

Himanshu Verma
Himanshu Verma 2020년 8월 26일
I've found a workaround for this problem. Instead of changing the foreground, I'm changing the background. The background color of each row is saved in a matrix containing the RGB values of each row of the table. This matrix is passed as a 'BackgroundColor' argument while displaying the uitable.

추가 답변 (1개)

Jyotsna Talluri
Jyotsna Talluri 2020년 5월 18일
편집: Jyotsna Talluri 2020년 5월 18일
You can make use of uistyle and addstyle functions
Refer to the documnetation link below
  댓글 수: 4
Himanshu Verma
Himanshu Verma 2020년 5월 18일
I checked it and tried at my end. When I enter the following code:
uitable('Data',{'<html><body text color="#FF0000">Hello</body></html>'});
We get a table with a cell in which 'Hello' is written in red color.
I already have a uifigure open and a uitable has been built as its child. When I try to enter the data in this table as:
uitable(fig,'Data',{'<html><body text color="#FF0000">Hello</body></html>'});
It does not recognise the html code but gives this as output:
What could be the issue?
Himanshu Verma
Himanshu Verma 2020년 5월 18일
As an alternative, is it possible to change the background color of each row? It should work like whenever I add a new row, the background color of that row should change as per the value of decision variable (cell_2 in this case).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by