addlistener error - updating from handle.listener
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am trying to edit a code which I didnt write that uses handle.listener in it. I am struggling to update it to meet the requirements of addlistener.
The original code is:
listener = handle.listener(parent_handle, ...
parent_handle.findprop(property), ...
'PropertyPostSet', update_fcn);
I have modified it to:
listener = addlistener(parent_handle, ...
parent_handle.findprop(property), ...
'PostSet', update_fcn);
However, I am still receiving the error message "While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not defined to be SetObservable."
How can i resolve this? Thanks!!
0 件のコメント
回答 (1 件)
Divyajyoti Nayak
2024 年 12 月 27 日
Hi Kaden,
According to the documentation of the ‘addlistener’ function, only properties whose class can set the ‘GetObservable’ and ‘SetObservable’ property attributes can be listened to. The ‘Position’ property of the figure object is not such a property and hence you are getting the error. Here’s some documentation on the property requirements of the ‘addlistener’ function:
I did find a workaround in StackOverflow that uses ‘JavaFrame’ to add a callback when the figure is moved. Here’s a sample code:
a = figure;
pause(0.2) % Wait for the figure construction complete.
jFig = get(a, 'JavaFrame'); % get JavaFrame. You might see some warnings.
jWindow = jFig.fHG2Client.getWindow;
jbh = handle(jWindow,'CallbackProperties'); % Prevent memory leak
set(jbh,'ComponentMovedCallback',@callback);
function callback(src,event)
disp('Update');
end
Here’s the link to the StackOverflow answer (the second answer by Y.Chang)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Handle Classes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!