uitable: setValueAt() ignores HTML code

조회 수: 1 (최근 30일)
Stephan Heise
Stephan Heise 2014년 3월 27일
댓글: Stephan Heise 2018년 7월 25일
Hi,
I use HTML to format the text color in cells of a uitable, e.g.
set(table_handle, 'Data',{'<html><font color="red">cell contents'});
If I later try to change the contents of that cell using the setValueAt method of the table's underlying jTable, the HTML formatting isn't changed, i.e. when using
jTable.setValueAt('new cell contents',0,0)
the new cell contents is still formatted red and if I click the cell to start editing it, I see that the HTML code is still there.
Any ideas how to also overwrite the HTML code without having to re-write the whole table using set(table_handle, 'Data',...) ?
(By the way, I know it would be more elegant to use a custom cell renderer...)
  댓글 수: 3
Stephan Heise
Stephan Heise 2014년 3월 27일
Sorry - I forgot that. Here is the code:
jscrollpane = findjobj(table_handle);
jTable = jscrollpane.getViewport.getView;
Stephan Heise
Stephan Heise 2014년 3월 31일
Maybe I should also mention that I try to set the cell value in the jTable's MousePressedCallback, i.e. in my GUI's OutputFcn I set
set(handle(jTable, 'CallbackProperties'), ...
'MousePressedCallback',{@table_MousePressedCallback, gcf});
and then later
function table_MousePressedCallback(jTable, jEventData, figure_handle)
...
jTable.setValueAt(newValue, jTable.rowAtPoint(jEventData.getPoint), jTable.columnAtPoint(jEventData.getPoint));
...

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

채택된 답변

Vineeta Chaturvedi
Vineeta Chaturvedi 2018년 6월 28일
Hi Stephan,
I understand you are trying to achieve certain functionality in uitable but using findjobj. Not sure the purpose of using findjobj and the use case where its required to use the setValue function.
Alternatively you can use the matlab uitable directly to achieve the required functionality.
Here is the code -
ut = uitable('Data',{'<html><font color="red">cell contents'})
ut.Data{1,1} = 'cell contents'
Thanks, Vineeta
  댓글 수: 1
Stephan Heise
Stephan Heise 2018년 7월 25일
Hi Vineeta,
thank you for pointing me towards this elegant solution! Since I had developed my code in HG1-times, I never thought of this...
Thanks, Stephan.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by