Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: add a uicontainer or uipanel to a JPanel
Date: Mon, 23 Feb 2009 18:14:02 +0000 (UTC)
Organization: TACT Computer Systems Ltd
Lines: 116
Message-ID: <gnup1a$89j$1@fred.mathworks.com>
References: <f9fvpk$t63$1@fred.mathworks.com> <f9hcmr$dhk$1@fred.mathworks.com> <f9hibi$m7t$1@fred.mathworks.com> <f9hje3$62v$1@fred.mathworks.com> <fc9ttj$eh5$1@fred.mathworks.com> <fch8o8$ee7$1@fred.mathworks.com> <fclie6$q6i$1@fred.mathworks.com> <figibp$3tn$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1235412842 8499 172.30.248.38 (23 Feb 2009 18:14:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 23 Feb 2009 18:14:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 642467
Xref: news.mathworks.com comp.soft-sys.matlab:520258


"Amir " <amir_ben-dor.nospam@nospam.agilent.com> wrote in message <figibp$3tn$1@fred.mathworks.com>...
> "Andrew Watson" <andruwatson@yahoo.co.uk> wrote in message
> <fclie6$q6i$1@fred.mathworks.com>...
> > "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> > <fch8o8$ee7$1@fred.mathworks.com>...
> > > "Bill York" <BillDotYork@MathWorks.com> wrote in message
> > > <fc9ttj$eh5$1@fred.mathworks.com>...
> > > > "Andrew Watson" <andruwatson@yahoo.co.uk> wrote in
> message 
> > > > <f9hje3$62v$1@fred.mathworks.com>...
> > > > > Thanks Yair,
> > > > > 
> > > > > An axis is ultimately what I wanted to add to to a
> JPanel
> > > > > but I figured that a uicontanier or uipanel in which an 
> > > > axis
> > > > > can sit might be more native to the Java environment.  
> > > > 
> > > > The short answer to the posted question is you can't do 
> > > > that.
> > > > 
> > > > The uicontainers and uipanels and axes, for that matter, 
> > > > just can't be put in arbitrary Java components. It's not 
> > > > that we don't want to make it possible, it's just a
> ton of 
> > > > work and other priorities keep coming up.
> > > > 
> > > > As for putting an axes in a Java container, you can
> use the 
> > > > print or imwrite commands to dump the contents of a
> figure 
> > > > into a bitmap then shove that into any Java canvas which 
> > > > can show a bitmap.  We've done some hackery where you
> take 
> > > > the output from imwrite and stuff it onto a JButton for 
> > > > example.
> > > > 
> > > > As for putting non-bitmap axes into Java containers,
> could 
> > > > you tell me more about why you want to do it?  What is
> the 
> > > > MATLAB thing you can't do without this capability?
> > > > 
> > > > Thanks,
> > > > 
> > > > Bill
> > > 
> > > 
> > > Thanks a lot for your comment Bill. It is sometimes
> > > important to place Matlab axes in Java containers, since
> > > Java (Swing in particular) enables richer GUI than Matlab
> > > enables. For example, if I need JSplitPane functionality I
> > > have to rely on Java, not Matlab, but then I cannot add a
> > > Matlab axes to either side of the split-pane, which is a
> > > major drawback. You'll agree with me, I hope, that
> > > reprogramming a JSplitPane from scratch in Matlab just to
> > > solve the axes issue would be a shameful waste...
> > > 
> > > Remember that Matlab axes (& children) are rich objects
> > > themselves, and simple imwrite falls far short of the needs
> > > (callbacks and online data updates are just two examples).
> > > 
> > > If only an axes could be placed within a JContainer, that
> > > would automatically solve all these issues, for all Swing
> > > components.
> > > 
> > > Yair Altman
> > > 
> > 
> > Bill,
> > 
> > At the time of posting I was looking for the same
> > functionality that Yair Altman has mentioned, that of a
> > JSplitPane.  It is not a trivial exercise to code one up
> > from scratch.  Also the results will never be as robust,
> > fluid or aesthetically pleasing as a JSplitPane.
> > 
> > Thanks for your suggestion of using imwrite or some other
> > such method but as Yair has pointed out, I also want to
> > maintain the functionality of an axis object i.e callbacks
> > and what not.
> > 
> > Andrew
> > 
> Bill, 
> 
> As you know from our past correspondence, there are ways (at
> least two I'm aware of) to make a java/matlab figure hybrid 
> that have java GUI and matlab graphic (aka "the holly
> grail"). However, both are non-trivial, non-intuitive, have
> limitations (for example, making sure the java components
> resize after the user resize the matlab figure) and require
> heavy usage of undocumented features. Moreover, it seems
> that new Matlab version frequently break such hacks that
> worked in the previous version (no real complains here, as
> those hacks use UNDOCUMENTED features). However, one gets
> tired from using those hacks and want to just implement the
> needed business logic instead of fighting with Java/Matlab
> integration issues.
> 
> Can you comment on when (if at all) will Mathwork be able to
> implement a java wrapper around matlab axis that extends
> java.com.Component, so we could just drop it inside our
> favorite java container as god intended and go on with our
> lives.  
> 
> Amir


For those interested, I've just uploaded a new contribution to the File Exchange called UISplitPane (http://www.mathworks.com/matlabcentral/fileexchange/23073), which mimics JSplitPane behavior with full Matlab support. This means that you can add axes and controls to the split-panes (2 uipanels), and they resize automatically when the split-pane divider is moved interactively or programatically. Feedback is most welcome.

Behind the scenes, the basis is much as Amir has hinted, and similar to the uitab/uitabgroup implementation: I've taken the divider portion of the JSplitPane and coupled it to 2 standard Matlab uipanels as sub-panes. Matlab axes and controls can now easily be added to the uipanels. Property listeners and schema property set-function setup then ensure consistency between the Java and Matlab parts. Special handling was added to ensure usability even in non-Java-enabled Matlabs (e.g., Matlab 6.0 aka R12).

I assume this alleviates a major need in Matlab-Java integration but the basic request from all responders in this thread remains unchanged, quoting Amir: *PLEASE* "implement a java wrapper around matlab axis that extends java.com.Component, so we could just drop it inside our favorite java container as god intended"

Yair Altman