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:
Java Gui with Matlab control

Subject: Java Gui with Matlab control

From: Alex Sietins

Date: 14 Apr, 2010 21:11:04

Message: 1 of 9

Hello all,

I'm building a laboratory program. I have the base (drivers and such) already built in MATLAB. However, I would rather use a Java GUI (prettier & easier).

What would be perfect is to have a Java GUI object that I could drop in to replace my existing MATLAB GUI object. Is there an easy and effective way to accomplish this?

Subject: Java Gui with Matlab control

From: Yair Altman

Date: 14 Apr, 2010 23:03:05

Message: 2 of 9

"Alex Sietins" <alexis.sietins@gmail.com> wrote in message <hq5b18$93r$1@fred.mathworks.com>...
> Hello all,
>
> I'm building a laboratory program. I have the base (drivers and such) already built in MATLAB. However, I would rather use a Java GUI (prettier & easier).
>
> What would be perfect is to have a Java GUI object that I could drop in to replace my existing MATLAB GUI object. Is there an easy and effective way to accomplish this?

You can customize Matlab GUI, which is basically Swing-based, for a much "sleeker"-looking appearance - see numerous articles on http://UndocumentedMatlab.com

You can easily use pure Java components in Matlab GUI, using the built-in undocumented/unsupported javacomponent function. You can also use alternatives such as uicomponent (http://www.mathworks.com/matlabcentral/fileexchange/14583) or JControl (http://www.mathworks.com/matlabcentral/fileexchange/15580). All these work within the Matlab framework and add AWT/Swing components to a Matlab figure.

Using other (non-Swing) Java GUI frameworks is also possible. A SWT example: http://www.mathworks.com/matlabcentral/newsreader/view_thread/69793

If you want to use a pure-Java GUI, you can create a class/JAR and simply call its gateway method (or class constructor) from within Matlab.

If you want the reverse (Java in control, calling Matlab as needed), you will need to use JMI: http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/

Yair Altman
http://UndocumentedMatlab.com

Subject: Java Gui with Matlab control

From: Øyvind

Date: 15 Apr, 2010 08:45:05

Message: 3 of 9

Adding swing uicontrols can certainly improve Matlab GUIs,
but the main problem, in my opinion, is making a good layout.
GUIDE will not help you achieve that, and even swing
components don't look good scattered haphazardly across
your GUI. Don't even think about resizing the window.

Writing the layout code by hand is challenging to say the
least, but there are some user-contributed layout managers
like GridBagLayout (http://www.mathworks.com/matlabcentral/fileexchange/22968-gridbaglayout) that make it a bit easier (still, too difficult for me,
I can never get things to look the way I want). You could check
that out, Alex.

If there is _one_ single topic I would love to see addressed
in Yair Altman's excellent blog (UndocumentedMatlab.com) it's
GUI layout (as opposed to discussing the uicontrols themselves).
I would suspect that there are java layout managers that are
available from Matlab -- or am I way off?

Subject: Java Gui with Matlab control

From: Alex Sietins

Date: 21 Apr, 2010 16:31:08

Message: 4 of 9

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hq5hj9$ks4$1@fred.mathworks.com>...
> "Alex Sietins" <alexis.sietins@gmail.com> wrote in message <hq5b18$93r$1@fred.mathworks.com>...
> > Hello all,
> >
> > I'm building a laboratory program. I have the base (drivers and such) already built in MATLAB. However, I would rather use a Java GUI (prettier & easier).
> >
> > What would be perfect is to have a Java GUI object that I could drop in to replace my existing MATLAB GUI object. Is there an easy and effective way to accomplish this?
>
> You can customize Matlab GUI, which is basically Swing-based, for a much "sleeker"-looking appearance - see numerous articles on http://UndocumentedMatlab.com
>
> You can easily use pure Java components in Matlab GUI, using the built-in undocumented/unsupported javacomponent function. You can also use alternatives such as uicomponent (http://www.mathworks.com/matlabcentral/fileexchange/14583) or JControl (http://www.mathworks.com/matlabcentral/fileexchange/15580). All these work within the Matlab framework and add AWT/Swing components to a Matlab figure.
>
> Using other (non-Swing) Java GUI frameworks is also possible. A SWT example: http://www.mathworks.com/matlabcentral/newsreader/view_thread/69793
>
> If you want to use a pure-Java GUI, you can create a class/JAR and simply call its gateway method (or class constructor) from within Matlab.
>
> If you want the reverse (Java in control, calling Matlab as needed), you will need to use JMI: http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/
>
> Yair Altman
> http://UndocumentedMatlab.com

I'm looking at the option of having a pure Java-GUI and calling it from within Matlab. Is there a way to tag a Matlab callback function to a java event?

Right now I'm using a polling system within the Matlab thread to check to see if there in an update from the GUI. This system is pretty clunky and has the chance of running into a race condition if I'm not careful. I'm not sure using the eval/feval commands from within Java will work properly for me (it depends on what local scope those commands are executed under).

Subject: Java Gui with Matlab control

From: Yair Altman

Date: 21 Apr, 2010 17:51:05

Message: 5 of 9

"Alex Sietins" <alexis.sietins@gmail.com> wrote in message

> I'm looking at the option of having a pure Java-GUI and calling it from within Matlab. Is there a way to tag a Matlab callback function to a java event?
>
> Right now I'm using a polling system within the Matlab thread to check to see if there in an update from the GUI. This system is pretty clunky and has the chance of running into a race condition if I'm not careful. I'm not sure using the eval/feval commands from within Java will work properly for me (it depends on what local scope those commands are executed under).

This is possible, but well outside the scope of a simple forum post. Contact me by email if you would like my assistance in this matter (for a fee).

Yair Altman
http://UndocumentedMatlab.com

Subject: Java Gui with Matlab control

From: Yair Altman

Date: 9 Jun, 2010 22:08:22

Message: 6 of 9

"Øyvind " <oyvist@gmail.com> wrote in message

> If there is _one_ single topic I would love to see addressed
> in Yair Altman's excellent blog (UndocumentedMatlab.com) it's
> GUI layout (as opposed to discussing the uicontrols themselves).
> I would suspect that there are java layout managers that are
> available from Matlab -- or am I way off?


Fresh out of the oven: http://UndocumentedMatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/

Yair Altman
http://UndocumentedMatlab.com

Subject: Java Gui with Matlab control

From: Øyvind

Date: 11 Jun, 2010 07:59:08

Message: 7 of 9

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hup3cm$6b2$1@fred.mathworks.com>...
> "Øyvind " <oyvist@gmail.com> wrote in message
>
> > If there is _one_ single topic I would love to see addressed
> > in Yair Altman's excellent blog (UndocumentedMatlab.com) it's
> > GUI layout (as opposed to discussing the uicontrols themselves).
> > I would suspect that there are java layout managers that are
> > available from Matlab -- or am I way off?
>
>
> Fresh out of the oven: http://UndocumentedMatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/
>
> Yair Altman
> http://UndocumentedMatlab.com

Yay! That's great! I'll have to study that blogpost when the crazyness at work simmers down.

Øyvind

Subject: Java Gui with Matlab control

From: Donn Shull

Date: 24 Jun, 2010 02:47:25

Message: 8 of 9

"Alex Sietins" <alexis.sietins@gmail.com> wrote in message <hqn98c$bgp$1@fred.mathworks.com>...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hq5hj9$ks4$1@fred.mathworks.com>...
> > "Alex Sietins" <alexis.sietins@gmail.com> wrote in message <hq5b18$93r$1@fred.mathworks.com>...
> > > Hello all,
> > >
> > > I'm building a laboratory program. I have the base (drivers and such) already built in MATLAB. However, I would rather use a Java GUI (prettier & easier).
> > >
> > > What would be perfect is to have a Java GUI object that I could drop in to replace my existing MATLAB GUI object. Is there an easy and effective way to accomplish this?
> >
> > You can customize Matlab GUI, which is basically Swing-based, for a much "sleeker"-looking appearance - see numerous articles on http://UndocumentedMatlab.com
> >
> > You can easily use pure Java components in Matlab GUI, using the built-in undocumented/unsupported javacomponent function. You can also use alternatives such as uicomponent (http://www.mathworks.com/matlabcentral/fileexchange/14583) or JControl (http://www.mathworks.com/matlabcentral/fileexchange/15580). All these work within the Matlab framework and add AWT/Swing components to a Matlab figure.
> >
> > Using other (non-Swing) Java GUI frameworks is also possible. A SWT example: http://www.mathworks.com/matlabcentral/newsreader/view_thread/69793
> >
> > If you want to use a pure-Java GUI, you can create a class/JAR and simply call its gateway method (or class constructor) from within Matlab.
> >
> > If you want the reverse (Java in control, calling Matlab as needed), you will need to use JMI: http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/
> >
> > Yair Altman
> > http://UndocumentedMatlab.com
>
> I'm looking at the option of having a pure Java-GUI and calling it from within Matlab. Is there a way to tag a Matlab callback function to a java event?
>
> Right now I'm using a polling system within the Matlab thread to check to see if there in an update from the GUI. This system is pretty clunky and has the chance of running into a race condition if I'm not careful. I'm not sure using the eval/feval commands from within Java will work properly for me (it depends on what local scope those commands are executed under).

You can use handle.listener to listen for Java events. The trick is to use handle to create the UDD companion for the Java Object. For example:

f = javax.swing.JFrame;
listen = handle.listener(f.handle, 'FocusGained', {@callback})

This will create a listener that will respond to the to the Java FocusGained event

Donn

Subject: Java Gui with Matlab control

From: Malcolm Lidierth

Date: 14 Jan, 2012 13:10:09

Message: 9 of 9

GImport at http://www.mathworks.com/matlabcentral/fileexchange/34235-making-matlab-swing-more provides a MATLAB class that let's you import a Java Swing-based GUI. It supports the use of MATLAB containers and JFrames and has methods that make working with the GUIs in a thread-safe way easy. It also has an option to install automatically install a layout that gives MATLAB-like behviour on resizing.

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