addlistener error - updating from handle.listener
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Divyajyoti Nayak
el 27 de Dic. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Handle Classes en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!