how to change each cell color in a uitable
Mostra commenti meno recenti
I wonder how can i make a uitable such that cells at this table has different background colorsand each column has different width
thank you
1 Commento
Emmanuelle Fried
il 28 Giu 2021
Use addStyle:
uit = uitable(...);
s = uistyle('BackgroundColor','red');
addStyle(uit,s,'column',2)
Risposta accettata
Più risposte (5)
Yair Altman
il 6 Giu 2013
8 voti
Philip
il 31 Mar 2017
6 voti
In Matlab 2017a (and at least as far back as 2013b) this has improved. The uitable now has a "BackgroundColor" property. This is an array of n rows and 3 columns, RGB values between 0 and 1. It appears that if this array has less rows than the data in the table, then the colours are repeated throughout the table.
To highlight a single row, create a colour array the same size as your data and specify the row of interest as the colour you want.
This is how the alternating row colours are created (and so those colours can be changed if you want as well).
1 Commento
Torsion27
il 24 Apr 2018
Hello, that is my way to try to get the GUI uitable BAckgroundColor changed. But it is only changing the whole uitable. I want it to just change the row of the checkbox green if the checkbox is 1 and if checkbox is 0, change to red background of the row. Thanks for your help. best regards
function pushbutton2_Callback(hObject, eventdata, handles)
global pushbutton
[num,txt,raw]= xlsread(uigetfile ({'.xlsx'}))anzahl_kriterien = size([raw],1)% --> aendern
kriterium = cell(anzahl_kriterien);
tabledata = [num2cell(true(length(raw),1)),raw];
set(handles.uitable3, 'data',tabledata) setappdata(handles.uitable3,'RawTableDat',raw)
% --- Executes when entered data in editable cell(s) in uitable3. function uitable3_CellEditCallback(hObject, eventdata, handles) tabledata=get(handles.uitable3,'Data');
spalte1=tabledata(:,1) spalte2=tabledata(:,2)
zeilenanzahl=length(tabledata);
% uitablehandles=findobj(handles.uitable3); for j = 1:1:zeilenanzahl %für zeile 1 bis ende
if (spalte1{j,1}==1) tabledata{j,2}=spalte2{j,1}set(handles.uitable3,'BackgroundColor',[0 1 0])
end
for j = 1:1:zeilenanzahl
if (tabledata{j,1}==0) tabledata{j,2}= set(handles.uitable3,'BackgroundColor',[1 0 0])end end end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function uitable3_CreateFcn(hObject, eventdata, handles)
hObject.ColumnFormat = {'logical',[]};
hObject.ColumnEditable = logical([1 0]);
Walter Roberson
il 31 Dic 2011
0 voti
4 Commenti
Mahmoud Hassan Eldally
il 3 Gen 2012
Walter Roberson
il 3 Gen 2012
You could try
'<HTML><TD BGCOLOR=#40FF68>Hello</TD>'
Mahmoud Hassan Eldally
il 3 Gen 2012
Rohail Razzaq
il 15 Apr 2015
what if i have to use a particular variable instead of a specific text in the following line :
html<font color="blue">'my text'</font></html>
Torsion27
il 22 Apr 2018
Modificato: Walter Roberson
il 23 Apr 2018
0 voti
Hey, i have a similar problem with a Gui uitable and it would be great if you can help me with that. Thaks a lot :)
Torsion27
il 24 Apr 2018
Hello, that is my way to try to get the GUI uitable BAckgroundColor changed. But it is only changing the whole uitable. I want it to just change the row of the checkbox green if the checkbox is 1 and if checkbox is 0, change to red background of the row. Thanks for your help. best regards
function pushbutton2_Callback(hObject, eventdata, handles)
global pushbutton
[num,txt,raw]= xlsread(uigetfile ({'.xlsx'}))
anzahl_kriterien = size([raw],1)% --> aendern
kriterium = cell(anzahl_kriterien);
tabledata = [num2cell(true(length(raw),1)),raw];%das nur einmal checkbox spalte da ist und am anfang
set(handles.uitable3, 'data',tabledata)
setappdata(handles.uitable3,'RawTableDat',raw)
% --- Executes when entered data in editable cell(s) in uitable3.
function uitable3_CellEditCallback(hObject, eventdata, handles)
tabledata=get(handles.uitable3,'Data');
spalte1=tabledata(:,1)
spalte2=tabledata(:,2)
zeilenanzahl=length(tabledata);
for j = 1:1:zeilenanzahl %für zeile 1 bis ende
if (spalte1{j,1}==1)
tabledata{j,2}=spalte2{j,1}
set(handles.uitable3,'BackgroundColor',[0 1 0])
end
for j = 1:1:zeilenanzahl
if (tabledata{j,1}==0)
tabledata{j,2}= set(handles.uitable3,'BackgroundColor',[1 0 0])
end
end
end
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function uitable3_CreateFcn(hObject, eventdata, handles)
hObject.ColumnFormat = {'logical',[]};
hObject.ColumnEditable = logical([1 0]);
1 Commento
Himanshu Verma
il 19 Mag 2020
Hi there...
Did you find any solution to this problem? I'm also looking for the same.
Categorie
Scopri di più su Data Import and Export in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
