Path: news.mathworks.com!not-for-mail
From: "Arwel Hughes" <a.v.hughes@rl.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Profiling Java in Matlab
Date: Mon, 12 Nov 2007 16:13:43 +0000 (UTC)
Organization: STFC Rutherford Appleton Laboratory
Lines: 83
Message-ID: <fh9u3n$779$1@fred.mathworks.com>
References: <fcqhf3$fcj$1@fred.mathworks.com> <feg3vs$6ha$1@fred.mathworks.com> <fgaj1g$imo$1@fred.mathworks.com> <fgatsr$e8r$1@fred.mathworks.com> <fgfmur$j3k$1@fred.mathworks.com>
Reply-To: "Arwel Hughes" <a.v.hughes@rl.ac.uk>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1194884023 7401 172.30.248.35 (12 Nov 2007 16:13:43 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 12 Nov 2007 16:13:43 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 408081
Xref: news.mathworks.com comp.soft-sys.matlab:437120



Hi Guys,
I too am very pleased to see these Java / ML issues being 
adressed! I'm writing an application at the moment which 
has a large, multi frame Swing MDI sitting on top of a 
Matlab program. It seems to be working okay, but I guess 
I've just been lucky as I've not taken any special 
precautions for threading issues, so I read the above with 
great interest.

My main approach is to deal with most of the Swing in their 
own pure classes, and invoke these from Matlab. But, 
there's been a great deal of bits where I've felt I havent 
been able to do this, because I didn't know how to access 
the 'ActionPerformedCallback' etc for objects instantiated 
in Java.
So for example, if I have something along the lines of....


import java.awt.*;
import javax.swing.*;

public class myButtons extends JFrame {
  public static void main(String[] args) {
    new myButtons();
  }

  public myButtons() {
    Container content = getContentPane();
    content.setLayout(new FlowLayout());
    JButton button1 = new JButton("Java");
    content.add(button1);
    button1.addActionListener(this)
    pack();
    setVisible(true);
  }
    
  public void ActionPerformed(ActionEvent event){
      !HOW TO GET THIS TO POINT TO MATLAB?!
}



...I have not been able to work out how to get Matlab 
respond to the button events. So, I've had to do this in ML 
on lots of things....


myFrame = JFrame();
button = JButton;
myFrame.getContentPane().add(button);
set(button,'ActionPerformedCallback',@myFun..


So it seems from the examples above that if I could find 
the relevant objects in a pure Swing made GUI, then I could 
use the 

button = handle(button,'callbackproperties');
set(button,'ActionPerformedCallback',@buttonClosePressed);

approach to set the callback to point to Matlab. This would 
actually be very nice indeed, as then in principle one 
could make a very nice looking GUI using something like the 
Netbeans GUI designer, and then just invoke this from 
Matlab, and use the 'handle' way of setting up the relevant 
callbacks??

Another drawback with my Swing based MDI of course is that 
I've not been able to put Matlab graphics into a Java 
container. I've had a look at Yair's  'GetJFrame' and hoped 
that I could just steal the underlying Jpanel from a matlab 
window and pop that into a Java frame, but when you do that 
it produces a whole load of errors because of the 
unexpected moving of the container, I think (something like 
that. I've not looked at this in detail). I suppose one 
would have to clone the container or something, but of 
course you can't clone a JPanel. Anyway, for now my MDI 
uses JFreeChart objects created from Matlab for the 
plotting, which is frustrating but it works.

Anyway, very good to see this thread.
Cheers,
arwel