5.0

5.0 | 10 ratings Rate this file 221 downloads (last 30 days) File Size: 33.31 KB File ID: #14583

UICOMPONENT - expands uicontrol to all Java classes

by Yair Altman

 

10 Apr 2007 (Updated 20 Jul 2007)

No BSD License  

Enhanced replacement for uicontrol & javacomponent, accepting all Java (Swing/AWT) style components

Download Now | Watch this File

File Information
Description

UICOMPONENT is intended as a direct replacement of Matlab's built-in UICONTROL and JAVACOMPONENT functions. It accepts all parameters and styles that UICONTROL accepts, as well as any other displayable Java (Swing/AWT) component class. The calling convention and syntax of UICONTROL were preserved for full backwards compatibility.

UICOMPONENT uses the built-in UICONTROL whenever possible (i.e, for all the standard styles), and uses JAVACOMPONENT to create and display all the other java classes. UICOMPONENT supports the entire Swing/AWT and any user-defined classes, in several equivalent case-insensitive formats. For example, 'Spinner', 'spiNNer', 'JSpinner' and 'javax.swing.jspinner' are all equivalent and recognized.

Notable new styles that are now available (unavailable in built-in UICONTROL): spinner, slider, editable comboBox, passwordField, tree, table, fileChooser, colorChooser, progressBar, applet. But there are so many more - whatever is available in Java is now seamlessly available in your Matlab GUI.

Examples (more examples in attached screenshot & in the help comment):
- uicomponent('style','jspinner','value',7); % simple spinner with initial value
- uicomponent('style','javax.swing.jslider','tag','myObj'); % simple horizontal slider
- uicomponent('style','JComboBox',{1,pi,'text'},'editable',true); % editable drop-down

Callbacks:
Over 30 callback hooks are exposed to the user for all components (the exact list depends on the specific java component used). These callbacks include mouse movement/clicks, keyboard events, focus gain/loss, data changes etc.

Warning:
This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!

Change log:
See the bottom of this page

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

Acknowledgements
This submission has inspired the following:
statusbar, passwordEntryDialog, UISplitPane - Split a container (figure/frame/uipanel) into two resizable sub-containers, Using java swing components in MATLAB
MATLAB release MATLAB 7.4 (R2007a)
Other requirements Java should be enabled (duh!) Should work on Matlab 7+, but might work on earlier versions too. Does NOT work on Matlab 6.5
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
11 Apr 2007 Matthew Whitaker

This is really fascinating. Note your example 1 and 2 should read:
uicomponent('Style','edit','String','hello');

and
uicomponent('Parent', fig2, 'Style', 'edit','String','hello');

instead of 'uicontrol'

I have not found any obvious issues although with the extensive use of non-documented features I'll have to test more extensively but this is a really nice wrapper for uicontrol and javacomponent. A lot of goodies in the code for anyone interested in incorporating Swing components into their interfaces.

22 May 2007 Arwel Hughes

This is an excellent tool. It works very well with a number of components I've tried.

27 Jun 2007 Malcolm Lidierth

Excellent. Produces great GUIs that work on both Windows and Mac without needing tweaking for each platform.

19 Jul 2007 Heiko Marx

After changing line 256 from strcmpi to strncmpi, because I use 'Visible' instead of 'vis', this excellent tool has made it to my daily use. Thank you very much!

18 Sep 2007 Dawn Song

Great TOOl ?

18 Sep 2007 Dawn Song

Oh, sorry, I mistyped, I meaned ! not ?

22 Sep 2007 Qun Han

Great!

04 Dec 2007 Jax Cao

Useful tool

30 Mar 2009 Jveer

the best gui related submission yet

30 Mar 2009 Jveer  
01 Apr 2009 Jveer

can these components be made transparent for e.g overlaying a transparent ticklabeled slider over a colorbar?

03 Apr 2009 Hans

Thanks for sharing this code with us, Yair. Whenever I need a java thingy that is not available in MATLAB, I use uicomponent.

Please login to add a comment or rating.
Updates
12 Apr 2007

Set large initial size for *Chooser classes; fixed Window subclasses issue; fixed help comment; enabled non-figure parent; enabled non-cell ctorArgs; set default Tag prop

18 May 2007

Handle pre-existing Java components

20 Jul 2007

Handle shortened property names per suggestion by H. Marx

Tag Activity for this File
Tag Applied By Date/Time
data exploration Yair Altman 22 Oct 2008 09:08:23
uicontrol Yair Altman 22 Oct 2008 09:08:23
javacomponent Yair Altman 22 Oct 2008 09:08:24
graphics Yair Altman 22 Oct 2008 09:08:24
java Yair Altman 22 Oct 2008 09:08:24
javacomponent li hoo 10 Nov 2008 18:13:49
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com