Changing the color if text in uitable
Show older comments
Hi all, I have a uitable and I want to display negative numbers in red, in my code I pass the numbers to text in order to get the format I want from java, heres my code:
function ColoredTable
table = uitable;
data = randn(3,6)*1000; %Just to generate some numbers with negative
DataSet = cell(size(data));
%I put the number format I want, but it makes the number a string
for i = 1:numel(data)
DataSet{i} = char(java.text.DecimalFormat('#,###,##0.00').format(Data(i)));
end
%In this line I try to acomplish the coloring, but fails.
DataReady = cellfun(@(x) colText(x, 'red'),strfind(DataReady,'-'),'UniformOutput',false);
%To set the table
set(table,'Data', DataReady,'Position', [1,1,800,100],'ColumnWidth',{86})
end
function outHtml = colText(inText, inColor)
% return a HTML string with colored font
outHtml = ['<font color="', ...
inColor, ...
'">', ...
inText, ...
'</font>'];
end
What I end up getting is a table with red squares, the "good" thing is that at least it's the actual cells that get changed, I thing that the cellfun function is not getting the actual text from the strfind, instead it get something else.
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!