addlistener error - updating from handle.listener
조회 수: 4 (최근 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!