Code covered by the BSD License  

Highlights from
UICOMPONENT - expands uicontrol to all Java classes

5.0
5.0 | 21 ratings Rate this file 51 Downloads (last 30 days) File Size: 58.4 KB File ID: #14583 Version: 1.2
image thumbnail

UICOMPONENT - expands uicontrol to all Java classes

by

Yair Altman (view profile)

 

10 Apr 2007 (Updated )

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

| 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 file inspired Password Entry Dialog, Spinner Demo, Control Google Earth Milktruck From Matlab, Using Java Swing Components In Matlab, Selectcolor.M, Ui Split Pane Split A Container (Figure/Frame/Uipanel) Into Two Resizable Sub Containers, and Statusbar.

MATLAB release MATLAB 7.4 (R2007a)
MATLAB Search Path
/
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   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
07 Apr 2015 Alain Barraud

Very useful and works fine with HG1 and HG2. A question how can I change BackGroundColor ForeGroundColor FontSize FontStyle... Such properties are not directly recognized through standard name/value pairs.
Many Thanks to Yair

01 Dec 2014 Tommie Heard

It did fix the error, but the Layout.Cell(1,3) object is not visible on the figure. Any idea why.
Thanks for the input.

Comment only
26 Nov 2014 Yair Altman

Yair Altman (view profile)

Your specified parent handle is probably wrong in some way. Try using gcf instead of Layout.Cell(1,3) to verify this.

Comment only
25 Nov 2014 Tommie Heard

handles.txtSeqFile = uicomponent( ...
'style','javax.swing.JTextField', ...
'parent',Layout.Cell(1,3), ...
'Tag', 'txtSeqFile', ...
'MouseClickedCallback',{@(handle,event)xMouseClick(handle,1)});



%----error after executing above line----

Error using javacomponentdoc_helper>applyArgumentsAndShow (line 197)
Invalid input

Error in javacomponentdoc_helper (line 35)

Error in javacomponent (line 111)
[hcomponent, hcontainer] = javacomponentdoc_helper(varargin{:});

Error in uicomponent (line 197)
[jcomp, hcontainer] = javacomponent(javaComp,position,parent);

What is causing this????

Comment only
20 Oct 2014 Dan

Dan (view profile)

Thanks!!

Comment only
20 Oct 2014 Yair Altman

Yair Altman (view profile)

Fixed - download the latest and retry.

Comment only
20 Oct 2014 Dan

Dan (view profile)

Thanks for this great tool, Yair.

I have problems using the latest version, though: In both HG (2014a) and HG2 (2014b), i get an error using the following syntax, which worked before:

h.fig = figure();
h.menu = uicomponent('Parent',h.fig,'style','JComboBox',{'A','B','C'},'editable',true);
h.menu.JavaComponent.getSelectedItem

error is: Attempt to reference field of non-structure array.

Do I have to change the syntax in the new version?

Thanks, Daniel

20 Oct 2014 Tom

Tom (view profile)

Thanks a lot Yair!

Comment only
10 Oct 2014 Yair Altman

Yair Altman (view profile)

@Tom - I've updated the utility for R2014b. Download the latest version. It should be backward compatible with earlier Matlab releases as well.

Comment only
08 Oct 2014 Tom

Tom (view profile)

Great submission. Getting errors when using with R2014b with all the graphics changes in that release. Any plans to update to support that release?

Comment only
10 Feb 2014 Amihay Blau

Wow!
A simple and amazing way to updgrade the UI.

Thank you

10 Feb 2014 Amihay Blau

Wow!
A simple and amazing way to updgrade the UI.

Thank yoy

31 Jan 2014 Pooya89  
20 Nov 2013 Caleb

Caleb (view profile)

Okay, I figured out the filter and the 'Open' and 'Cancel' buttons, but still can't figure out the icons.

Comment only
20 Nov 2013 Caleb

Caleb (view profile)

Thank you so much for this submission; I'm finding that it's very powerful and well thought out. I was wondering if someone could help me, though. I'm trying to create my own file chooser so that I'm able to add some check boxes to it. I've got that part down, but I'm not sure how to correctly create my own file filter, add callbacks to the 'Open' and 'Cancel' push buttons, and add icons to the buttons to the right of the directory selection drop down menu. I've tried setting the 'ActionPerformedCallback' property, but for some reason the callback function is only called when I click the 'Cancel' button.

08 May 2013 Peter

Peter (view profile)

 
28 Jun 2011 Gaurav Gupta

Gaurav Gupta (view profile)

Awesome job, but can u please tell me why uicontrol objects not hide when their position is out of parent uipanel area.

Comment only
24 Jun 2011 Isaac

Isaac (view profile)

It may not be obvious to the novice, but one experienced builder appreciates having access to all the "stuff" in a uniform interface. YMMV. (Thanks, Yair!)

Comment only
24 Jun 2011 Isaac

Isaac (view profile)

 
23 Jun 2011 B_Richardson

Can someone explain to a novice GUI builder the significance of this download?

Comment only
25 May 2010 Chris Rodgers

Great idea!

08 May 2010 shrey sinha  
27 Dec 2009 Evgeny Pr

Evgeny Pr (view profile)

It is fine!
I knew that in Matlab it is possible to do such, but you have made it very well! Thanks!

03 Apr 2009 Hans

Hans (view profile)

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

01 Apr 2009 Jveer

Jveer (view profile)

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

Comment only
30 Mar 2009 Jveer

Jveer (view profile)

 
30 Mar 2009 Jveer

Jveer (view profile)

the best gui related submission yet

Comment only
04 Dec 2007 Jax Cao

Useful tool

22 Sep 2007 Qun Han

Great!

18 Sep 2007 Dawn Song

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

18 Sep 2007 Dawn Song

Great TOOl ?

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!

27 Jun 2007 Malcolm Lidierth

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

22 May 2007 Arwel Hughes

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

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.

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

10 Oct 2014 1.1

Fixed for R2014b (HG2)

20 Oct 2014 1.2

Fixed a bug in setting the JavaComponent field

Contact us