Is there a way to add something like a
"ComponentMovedCallback" to a figure? Its possible to add
this callback to JFrame. I want to raise an event if the
figure is moving.
"Rico Saupe" <rico.saupe@valentum.de> wrote in message
<fgvc9v$ja8$1@fred.mathworks.com>...
> Hi
>
> Is there a way to add something like a
> "ComponentMovedCallback" to a figure? Its possible to add
> this callback to JFrame. I want to raise an event if the
> figure is moving.
>
> jb = JFrame();
> set(jb,'ComponentMovedCallback',{@funMove});
>
> Need the same for a figure
>
> f = figure;
> set(f,....)
jframe = get(f,'JavaFrame');
% ...and you know the rest
Thank you, I've tried it before, but it did not work.
f=figure;
jb = get(f,'JavaFrame');
set(jb,'ComponentMovedCallback',{@funMove});
% isn't working, because jb is of type
com.mathworks.hg.peer.FigurePanel and not javax.swing.JFrame
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fgvu1v$6j3$1@fred.mathworks.com>...
> "Rico Saupe" <rico.saupe@valentum.de> wrote in message
> <fgvc9v$ja8$1@fred.mathworks.com>...
> > Hi
> >
> > Is there a way to add something like a
> > "ComponentMovedCallback" to a figure? Its possible to add
> > this callback to JFrame. I want to raise an event if the
> > figure is moving.
> >
> > jb = JFrame();
> > set(jb,'ComponentMovedCallback',{@funMove});
> >
> > Need the same for a figure
> >
> > f = figure;
> > set(f,....)
>
>
> jframe = get(f,'JavaFrame');
> % ...and you know the rest
>
> Yair Altman
> http://ymasoftware.com
>
"Rico Saupe" <rico.saupe@valentum.de> wrote in message
<fh123b$cmm$1@fred.mathworks.com>...
> Thank you, I've tried it before, but it did not work.
>
> f=figure;
> jb = get(f,'JavaFrame');
> set(jb,'ComponentMovedCallback',{@funMove});
> % isn't working, because jb is of type
> com.mathworks.hg.peer.FigurePanel and not javax.swing.JFrame
>
> Maybe I should try something like this
>
> compl =
com.mathworks.hg.peer.FigurePeerComponentListener(???);
> jb.addFigurePeerComponentListener(compl);
>
> But with what parameters? It's not documented.
ok, the following works:
jf=get(f,'JavaFrame');
jb=jf.fFigureClient.getFrameProxy;
set(jb,'ComponentMovedCallback',@funMove);
note: you don't need {} around your @funMove unless you add
user-specified extra args.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.mathworks.jmi.bean.MatlabBeanInterface.addCallback(MatlabBeanInterface.java:691)
at
com.mathworks.jmi.bean.MatlabCallbackInterface.addCallback(MatlabCallbackInterface.java:128)
Caused by: java.lang.Error: FigureFrame object is NULL
at
com.mathworks.hg.peer.FigureFrameProxy.getClientFrame(FigureFrameProxy.java:208)
at
com.mathworks.hg.peer.FigureFrameProxy.addComponentListener(FigureFrameProxy.java:285)
... 6 more
It seems that the figure object is not fully created when
the second line is executed.
It doesn't happen if i step through the code with F9. So far
so good.
Is there a way to prevent this error?
Rico
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fh13j5$6io$1@fred.mathworks.com>...
> "Rico Saupe" <rico.saupe@valentum.de> wrote in message
> <fh123b$cmm$1@fred.mathworks.com>...
> > Thank you, I've tried it before, but it did not work.
> >
> > f=figure;
> > jb = get(f,'JavaFrame');
> > set(jb,'ComponentMovedCallback',{@funMove});
> > % isn't working, because jb is of type
> > com.mathworks.hg.peer.FigurePanel and not javax.swing.JFrame
> >
> > Maybe I should try something like this
> >
> > compl =
> com.mathworks.hg.peer.FigurePeerComponentListener(???);
> > jb.addFigurePeerComponentListener(compl);
> >
> > But with what parameters? It's not documented.
>
> ok, the following works:
> jf=get(f,'JavaFrame');
> jb=jf.fFigureClient.getFrameProxy;
> set(jb,'ComponentMovedCallback',@funMove);
>
> note: you don't need {} around your @funMove unless you add
> user-specified extra args.
>
> Download my FindJObj submission from the File Exchange to
> see the Java component hierarchy underlying the Matlab GUI:
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14317
>
> Yair Altman
> If i run this code, using F5 (means all at once)
>
> f=figure;
> jf=get(f,'JavaFrame');
> jb=jf.fFigureClient.getFrameProxy;
> set(jb,'ComponentMovedCallback',@funMove);
>
> I get this error <snip>
>
> It seems that the figure object is not fully created when
> the second line is executed.
> It doesn't happen if i step through the code with F9. So
> far so good. Is there a way to prevent this error?
>
> Rico
Add a call to drawnow to let the figure time to fully
render. You might also add calls to pause(0.001) to ensure
the main thread relinquishes control. I usually do both.
Complex GUI requires a larger pause. I won't get into the
details of why this happens or what the "proper" way to
solve it is - the important thing is that it works.
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fh1942$d2q$1@fred.mathworks.com>...
> > If i run this code, using F5 (means all at once)
> >
> > f=figure;
> > jf=get(f,'JavaFrame');
> > jb=jf.fFigureClient.getFrameProxy;
> > set(jb,'ComponentMovedCallback',@funMove);
> >
> > I get this error <snip>
> >
> > It seems that the figure object is not fully created when
> > the second line is executed.
> > It doesn't happen if i step through the code with F9. So
> > far so good. Is there a way to prevent this error?
> >
> > Rico
>
> Add a call to drawnow to let the figure time to fully
> render. You might also add calls to pause(0.001) to ensure
> the main thread relinquishes control. I usually do both.
> Complex GUI requires a larger pause. I won't get into the
> details of why this happens or what the "proper" way to
> solve it is - the important thing is that it works.
>
> Yair Altman
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fh1942$d2q$1@fred.mathworks.com>...
> > If i run this code, using F5 (means all at once)
> >
> > f=figure;
> > jf=get(f,'JavaFrame');
> > jb=jf.fFigureClient.getFrameProxy;
> > set(jb,'ComponentMovedCallback',@funMove);
> >
> > I get this error <snip>
> >
> > It seems that the figure object is not fully created when
> > the second line is executed.
> > It doesn't happen if i step through the code with F9. So
> > far so good. Is there a way to prevent this error?
> >
> > Rico
>
> Add a call to drawnow to let the figure time to fully
> render. You might also add calls to pause(0.001) to ensure
> the main thread relinquishes control. I usually do both.
> Complex GUI requires a larger pause. I won't get into the
> details of why this happens or what the "proper" way to
> solve it is - the important thing is that it works.
>
> Yair Altman
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fh1942$d2q$1@fred.mathworks.com>...
> > If i run this code, using F5 (means all at once)
> >
> > f=figure;
> > jf=get(f,'JavaFrame');
> > jb=jf.fFigureClient.getFrameProxy;
> > set(jb,'ComponentMovedCallback',@funMove);
> >
> > I get this error <snip>
> >
> > It seems that the figure object is not fully created when
> > the second line is executed.
> > It doesn't happen if i step through the code with F9. So
> > far so good. Is there a way to prevent this error?
> >
> > Rico
>
> Add a call to drawnow to let the figure time to fully
> render. You might also add calls to pause(0.001) to ensure
> the main thread relinquishes control. I usually do both.
> Complex GUI requires a larger pause. I won't get into the
> details of why this happens or what the "proper" way to
> solve it is - the important thing is that it works.
>
> Yair Altman
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.