Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to notify Matlab about Java object change in Matlab Java

Subject: How to notify Matlab about Java object change in Matlab Java

From: St. Gold

Date: 21 Apr, 2009 14:26:35

Message: 1 of 7

Hello,

Does anybody has any idea how to update Matlab function about Java
object change ?

It could be done by polling:

while JavaObj.getValue()=='not done yet'
  pause(1);
end

But polling is evil. There should be more elegant way to do this
job ...

I've checked 'Matlab Java Interface' docs :
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f6671.html
, but found nothing on the subject :(


Thanks in advance for your help,

Subject: How to notify Matlab about Java object change in Matlab Java

From: Malcolm Lidierth

Date: 21 Apr, 2009 14:44:02

Message: 2 of 7

Could you use javacomponent to set up the object, and set a callback to repond to the changed value?

Subject: How to notify Matlab about Java object change in Matlab Java

From: stasgold

Date: 21 Apr, 2009 15:42:15

Message: 3 of 7

On Apr 21, 5:44=A0pm, "Malcolm Lidierth" <ku.ca....@htreidil.mloclam>
wrote:
> Could you use javacomponent to set up the object, and set a callback to r=
espond to the changed value?

Hi Malcolm Lidierth,

I had no clue about javacomponent existence (no wonder it's
undocumented ), thanks for providing the feedback :)

It looks I will use it in the case I won't find a way to set a Matlab
callback from standard java JFrame container ( instead of embedding
swing components into Matlab figure )

I've checked out a possible usage of "waitfor" for this purpose :

waitfor(JavaObj,some_field,value)

It doesn't seem to work :(

Maybe someone of matlab developers would be so nice to share with us
his thoughts on this subject ... :)

Subject: How to notify Matlab about Java object change in Matlab Java

From: Malcolm Lidierth

Date: 21 Apr, 2009 16:13:02

Message: 4 of 7

If you are using swing components, you might take a look at Yair Altman's uicomponent or my own jcontrol class on the FEX.
http://www.mathworks.com/matlabcentral/fileexchange/15580
Both provide access to the MATLAB container and the underlying swing component through a single object.
A MATLAB figure can not parent a JFrame to the best of my knowledge but you can build GUIs in e.g. a JPanel contained in an ML figure easily enough.

Subject: How to notify Matlab about Java object change in Matlab Java

From: Yair Altman

Date: 21 Apr, 2009 16:59:02

Message: 5 of 7

> It looks I will use it in the case I won't find a way to set a Matlab
> callback from standard java JFrame container ( instead of embedding
> swing components into Matlab figure )

You can set Matlab callbacks for any Java object (including your JFrame) as follows:

hObject = handle(jObject,'callbackProperties'); % jObject is your java object reference
set(hObject,'WidowIconifiedCallback',@myMatlabFcn); % for example

To see the list of all supported callbacks etc., you can use my UIINSPECT (http://www.mathworks.com/matlabcentral/fileexchange/17935 ) or FINDJOBJ (http://www.mathworks.com/matlabcentral/fileexchange/14317 ) submissions on the File Exchange.

Yair Altman
http://UndocumentedMatlab.com
 

Subject: How to notify Matlab about Java object change in Matlab Java

From: stasgold

Date: 22 Apr, 2009 07:43:09

Message: 6 of 7

On Apr 21, 7:59=A0pm, "Yair Altman" <altmany...@gmailDEL.comDEL> wrote:
> > It looks I will use it in the case I won't find a way to set a Matlab
> > callback from standard java JFrame container ( instead of embedding
> > swing components into Matlab figure )
>
> You can set Matlab callbacks for any Java object (including your JFrame) =
as follows:
>
> hObject =3D handle(jObject,'callbackProperties'); =A0% jObject is your ja=
va object reference
> set(hObject,'WidowIconifiedCallback',@myMatlabFcn); =A0% for example
>
> To see the list of all supported callbacks etc., you can use my UIINSPECT=
 (http://www.mathworks.com/matlabcentral/fileexchange/17935) or FINDJOBJ (h=
ttp://www.mathworks.com/matlabcentral/fileexchange/14317) submissions on th=
e File Exchange.
>
> Yair Altmanhttp://UndocumentedMatlab.com

Thanks Yair,

Your post helped me big way. I just wonder how your tools are not yet
a part of standard Matlab distribution ...

UndocumentedMatlab.com is bookmarked as well :) Keep up the good work.

Subject: How to notify Matlab about Java object change in Matlab Java

From: Yair Altman

Date: 28 Jul, 2009 09:47:03

Message: 7 of 7

For those interested, I posted an article about undocumented Matlab-Java callbacks here: http://undocumentedmatlab.com/blog/uicontrol-callbacks/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

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.

Contact us