addStyle fails to change tree appearance
Show older comments
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
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!