Create listener for changes in position of a figure window

9 vues (au cours des 30 derniers jours)
Matt J
Matt J le 17 Mai 2021
Commenté : Matt J le 18 Mai 2021
I have been trying to use addlistener() to make it so that when one figure window is moved, another figure window shifts position by the same amount, so that their relative positions are always the same:
h1=figure(1);
plot(1:5);
h2=figure(2);
imshow(imread('cameraman.tif'));
addlistener(h2,'Position','PostSet', @(s,e)callback(s,e,h1))
function callback(h2,~,h1)
h1.Position(1:2)=h2.Position(1:2)-[500,0];
end
However, this results in,
Error using matlab.ui.Figure/addlistener
While adding a PostSet listener, property 'Position' in class 'matlab.ui.Figure' is not defined to be
SetObservable.
Error in test (line 8)
addlistener(h2,'Position','PostSet', @(s,e)callback(s,e,h1))
Does anyone know of a workaround that will allow me to do this?

Réponse acceptée

Jonas
Jonas le 17 Mai 2021
Modifié(e) : Rik le 17 Mai 2021

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by