Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Component Moved

Subject: Component Moved

From: Rico Saupe

Date: 8 Nov, 2007 16:08:32

Message: 1 of 9

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,....)


Thanks for your help.

Rico

Subject: Component Moved

From: Yair Altman

Date: 8 Nov, 2007 21:11:27

Message: 2 of 9

"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

Subject: Component Moved

From: Rico Saupe

Date: 9 Nov, 2007 07:26:35

Message: 3 of 9

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.


Bye, Rico


"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
>

Subject: Component Moved

From: Yair Altman

Date: 9 Nov, 2007 07:52:05

Message: 4 of 9

"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

Subject: Component Moved

From: Rico Saupe

Date: 9 Nov, 2007 08:57:21

Message: 5 of 9

It worked.
Concerning "{@funMove}". I know what you mean, but i'm going
to use some parameters. But thanks for help.

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.

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

Subject: Component Moved

From: Yair Altman

Date: 9 Nov, 2007 09:26:26

Message: 6 of 9

> 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

Subject: Component Moved

From: Rico Saupe

Date: 9 Nov, 2007 10:02:42

Message: 7 of 9

Thank you for helping. It's working.

Rico

"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

Subject: Component Moved

From: Rico Saupe

Date: 9 Nov, 2007 10:03:18

Message: 8 of 9

Thank you for helping. It's working.

Rico

"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

Subject: Component Moved

From: Rico Saupe

Date: 9 Nov, 2007 10:04:29

Message: 9 of 9

Thank you. That helped me alot.

Rico

"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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
java Yair Altman 9 Nov, 2007 08:10:37
undocumented Yair Altman 8 Nov, 2007 16:15:28
callback java jframe event figure Rico Saupe 8 Nov, 2007 11:10:02
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics