Figure uitable does not display html image in 2019b

I have been using html tags to display images in a uitable as suggested in this answer https://uk.mathworks.com/matlabcentral/answers/1132-display-an-icon-in-png-format-in-a-cell-of-a-uitable.
This worked fine when I was using 2018a, but now I have moved to 2019b it seems to have stopped working. I can still use html to change test font, background colour etc. but I just cannot get an image to display.
This is the code I use, tick is a 16x16 pixel png image.
fig = figure;
t = uitable('Parent', fig,...
'Data', {'1';'2';'3'},...
'ColumnName',[],...
'RowName',[],...
'ColumnWidth', {100});
tick = get_full_filename('+images\Completed_16.png');
t.Data(:,2) = {['<html><img src="file:/', tick, '"></html>']};
When I run this code in 2018a I get this output where I can see the png images in the second column of my table:
But when I run the code in 2019b I get this output where there are no images:
Any ides why I cannot get it to work anymore? Has the functionality changed?

6 comentarios

Adam Danz
Adam Danz el 18 de Dic. de 2019
This is the problem with using undocumented features. I'd be happy to tinker with it if you provide the image file any any other variables needed to recreate the problem in r2019b.
Evan
Evan el 18 de Dic. de 2019
Thanks Adam. Yes I know, its just so uselful that it would be a shame to lose it. Just wonder if I am doing anything wrong or if there is a way to get it working again.
The image is attached.
What does get_full_filename() do?
When I try this in r2018a the image doesn't load.
tick ='Completed_16.png';
t.Data(:,2) = {['<html><img src="file:/', tick, '"></html>']};
It just gets the full path as I had it in a package folder, sorry I've just remembered it's not a built in function.
If I replace it with this then it works for me.
fig = figure;
t = uitable('Parent', fig,...
'Data', {'1';'2';'3'},...
'ColumnName',[],...
'RowName',[],...
'ColumnWidth', {100});
% tick = get_full_filename('+images\Completed_16.png');
tick = 'C:\Users\evan\Workspaces\Trunk\Common\+images\Completed_16.png';
t.Data(:,2) = {['<html><img src="file:/', tick, '"></html>']};
Adam Danz
Adam Danz el 19 de Dic. de 2019
Editada: Adam Danz el 24 de En. de 2020
I thinkered around with it a bit but couldn't get any good results for r2019b.
This thread lists common problems and might be helpful to browse.
Update: See Arno van der Heijden's answer below.
Evan
Evan el 19 de Dic. de 2019
Ok, well thanks for having a look.

Iniciar sesión para comentar.

 Respuesta aceptada

I struggled with this as well and eventually realised that it still works as long as you explicitly define the image size!:
t.Data(:,2) = {['<html><img src="file:/', tick, '" height="16" width="16"></html>']};

3 comentarios

Adam Danz
Adam Danz el 24 de En. de 2020
Good find! +1
Dev-iL
Dev-iL el 9 de Feb. de 2020
Thanks for sharing! +1
Evan
Evan el 13 de Feb. de 2020
Thanks Arno

Iniciar sesión para comentar.

Más respuestas (1)

Yair Altman
Yair Altman el 24 de Dic. de 2019
Editada: Yair Altman el 24 de Dic. de 2019
It's not just in tables. For some reason <img> tags are now ignored in all uicontrols (inc. buttons, listboxes etc.). There is no problem with your code, except for the fact that you forgot the step of:
tick = strrep(tick, '\', '/');
But even after adding this missing step, the images still don't render, although other HTML code does render. For example: uicontrol('String', '<html>12<img...>34') will display "1234" without the image in the middle. Other HTML tags (for example, <b>, <i>, <font>, <div> etc.) still work ok, but not <img>.
I have not yet discovered a workaround, nor do I fully understand the root cause.
Until then, you could use unicode character U+2705 (&#9989 - , which is part of the Dingbats character block) as follows:
t.Data(:,2) = {'<html><font color="green"><b>&#9989'};
uitable-with-checkmark.png
(note the use of bold green color, otherwise the "character" displays using the default light black)
Other alternatives, obviously much more cumbersome, are to display the image using either CSS or by using the underlying Java component and using its column CellRenderer to display the image.

2 comentarios

Evan
Evan el 2 de En. de 2020
Thanks Yair, using the dingbats characters are a good workaround for me.
This is a great answer still today, @Yair Altman and works around the <img> tag not working in uitable(uifigure). Thanks!

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 18 de Dic. de 2019

Comentada:

el 18 de Nov. de 2025

Community Treasure Hunt

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

Start Hunting!

Translated by