addStyle fails to change tree appearance

5 views (last 30 days)
I am attempting to programmatically change the background color of certain tree nodes based on the state of something else in my Matlapp. I found the documentation for uiStyle and addStyle, so I started to play with the minimal examples. However, the posted example code on these pages does not actually work:
fig = uifigure('Position',[100 100 250 350]);
t = uitree(fig);
fignode = uitreenode(t,'Text','UI Figure');
pnlnode = uitreenode(fignode,'Text','Panel');
axnode = uitreenode(fignode,'Text','UIAxes');
btnnode = uitreenode(pnlnode,'Text','Button');
ddnode = uitreenode(pnlnode,'Text','DropDown');
expand(t,'all')
s1 = uistyle('BackgroundColor','#3773EB');
s2 = uistyle('BackgroundColor','#78A1F2');
s3 = uistyle('BackgroundColor','#B5CBF8');
addStyle(t,s1,'level',1);
addStyle(t,s2,'level',2);
addStyle(t,s3,'level',3);
Returns an error:
Check for incorrect argument data type or missing argument in call to function 'addStyle'.
Error in test (line 74) addStyle(t,s1,'level',1);
Using lasterror gives: ans =
struct with fields:
message: 'Cannot access method 'getController' in class 'matlab.ui.container.Tree'.'
identifier: 'MATLAB:class:MethodRestricted'
stack: [6×1 struct]
Example code that uses tables instead of trees works fine. But for my application, I need to use a tree to display my data.
What is going on, and can I overcome this error without switching to a newer version of Matlab?

Accepted Answer

Thomas Carlson
Thomas Carlson on 7 Apr 2022
This problem seems to be fixed in R2022a.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!