Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matlab Figure into a Java Container??

170 views
Skip to first unread message

Arwel Hughes

unread,
May 22, 2007, 5:13:40 AM5/22/07
to
Hi,

I'm making an MDI on top of Matlab (with JDesktopPane), and it would
be nice to be able to include Matlab figures in it. One way would be
if you could put a Matlab figure into a Java container (in this case
JInternalFrame) but I suspect this is not possible... unless someone
has found some undocumented stuff.
The alternative would be to abandon Matlab grapohics and just pass
the data to a suitable Java class for plotting in the MDI, but that
seems a shame.
Any ideas?
Cheers,
Arwel.

Yair Altman

unread,
May 22, 2007, 7:00:41 AM5/22/07
to
Matlab figures are basically Java JFrames. To get the Java frame,
simply use the undocumented get(hFig,'JavaFrame').

I suggest you download FINDJOBJ from the File Exchange to find out
how Matlab figures and components are implemented using Java Swing
components. If you use FINDJOBJ with no output params it displays a
graphical listing of the component hierarchy. This will make it
easier for you to decide how to incorporate Matlab figs into your
MDI.

Yair Altman

Arwel Hughes

unread,
May 22, 2007, 8:12:23 AM5/22/07
to
Hi Yair,
Wow! Okay, this is very interesting but also complicated!
I need to get it clear in my what I'm trying to do here I think!

In the ideal case I suppose, it would be to hijack 'plot' so that I
could send plots to an axis in a panel in my Java gui. So
plot(hx,...) would point to matlab axes siting in a Java container.

Alternatively, I imagine it would be possible to plot the figure in
Matlab (but hidden), and then take the appropriate component from
this (i.e. the content pane containing the completed figure) and then
put the fully completed figure in my Java container.

Option 2 seems the most reasonable. Do you think this will work?? If
so, I would really welcome some clues as to how this might be done if
you know!

Many Thanks,
Arwel

Yair Altman

unread,
May 22, 2007, 9:20:42 AM5/22/07
to
Hi Arwel:

> In the ideal case I suppose, it would be to hijack 'plot' so that I
> could send plots to an axis in a panel in my Java gui. So
> plot(hx,...) would point to matlab axes siting in a Java container.

Unfortunately, it seems we cannot add Matlab axes (or any other
Matlab component) to a non-Matlab container like JPanel, despite this
being requested from TMW years ago (not by me). Moreover, Matlab axes
are virtual objects - the physical drawing is apparently done
directly on the Graphics canvas, and so is not accessible. So unless
I learn something new, this option appears impossible.

Regarding the second option, it looks reasonable at first glance. I
would search Java forums for hints on how to implement this, as this
becomes an almost pure-Java question.

Yair Altman

0 new messages