% h.javaComponent.addItem('text2'); % adding data to the drop-down post-creation
% h.ActionPerformedCallback = @myMatlabFunction; % setting a callback
% uicomponent(h); % sets the focus to component h (enabled keyboard actions)
% string = h.JavaComponent.getSelectedItem; % get the currently selected item
% string = get(h,'selecteditem'); % equivalent way to do the same thing
% string = h.sElEcTeDiTeM; % ...a 3rd way to do the same (note case insensitivity)
%
% Callbacks:
% Over 30 callback hooks are exposed to the user (the exact list depends on the selected
% style). These callbacks include mouse movement/clicks, keyboard events, focus gain/loss,
% data changes etc. In most cases, the user would be concerned mainly with the
% 'StateChangedCallback', which is triggered whenever some property of the component has
% changed (position, value etc.). In some cases, 'StateChangedCallback' is unavailable
% and the user should use alternative callbacks, like 'ActionPerformedCallback'. Type
% 'set(hcomponent)' for the full list of callbacks supported by your specific hcomponent.
%
% Programming tips:
% 1) Unless UICONTROL is used, the returned hcomponent contains 2 useful properties:
% - JavaComponent - a reference to the created java component.
% - MatlabHGContainer - the numeric handle h to the Matlab HG container. This is the
% value returned by the findall/finobj matlab functions. You can still get/set all the
% component properties using this numeric handle, but they'd be hidden unless you use
% handle(h) or hcomponent, which is the same thing.
% 2) JAVACOMPONENT normally sets the container's UserData property to the classname of the
% component (a string). This UICOMPONENT sets UserData to a reference to hcomponent, to
% make it easy for novice users to see all properties without using handle().
% 3) The user is referred to <a href="http://java.sun.com/docs/books/tutorial/uiswing/index.html">Sun's official Swing Tutorial</a>
%
% Warning:
% This code heavily relies on undocumented and unsupported Matlab functionality.
% It works on Matlab 7+, but use at your own risk!
%
% Bugs and suggestions:
% Please send to Yair Altman (altmany at gmail dot com)
%
% Change log:
% 2007-Apr-10: First version posted on MathWorks file exchange: <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14583">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14583</a>
% 2007-Apr-12: 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
% We get here for all parents not accepted by JAVACOMPONENT as valid parents - try a workaround
%error('YMA:uicomponent:InvalidParentType','Invalid parent container specified - only figure/panel handles are accepted');
warning('YMA:uicomponent:NonFigureParent','Non-figure parent was specified - using the parent''s figure as the component''s parent\n(Type "<a href="matlab:warning off YMA:uicomponent:NonFigureParent">warning off YMA:uicomponent:NonFigureParent</a>" to suppress this warning.)');
parentPosition = getpixelposition(parent,true);
if isempty(position)
position = [20,20,60,20]; % default position = bottom-left corner of parent
end
position = position + [parentPosition(1:2),0,0]; % pixel position relative to figure