File Exchange

image thumbnail

findjobj - find java handles of Matlab graphic objects

version (182 KB) by Yair Altman
Find java objects contained within a specified java container or Matlab GUI handle


Updated 15 Dec 2019

View Version History

View License

Find all java objects contained within a java container or Matlab GUI handle

If no output parameter is specified, then an interactive GUI window will be displayed with a tree-view of all container components, their properties and callbacks.

[handles,levels,parentIds,listing] = findjobj(container,'PropName',PropValue(s),...)

- container - optional GUI handle. If unsupplied then current figure will be used
- 'PropName',PropValue - optional list of case insensitive property pairs. PropName may also be named -PropName.

Supported properties:
- 'position' - filter results based on those elements that contain the specified X,Y position or a java element
Note: specify a Matlab position (X,Y = pixels from bottom left corner), not a java one
- 'size' - filter results based on those elements that have the specified W,H (in pixels)
- 'class' - filter results based on those elements that contain the substring (or java class) PropValue
Note: filtering is case insensitive and relies on regexp, so you can pass wildcards etc.
- 'property' - filter results based on elements that possess the specified case-insensitive property string or have property values in cell array format: {'propName', 'propValue'}. Example: findjobj(...,'property', {'Text','click me'})
- 'depth' - filter results based on specified depth. 0=top-level, Inf=all levels (default=Inf)
- 'flat' - same as: 'depth',0
- 'not' - negates the following filter: 'not','class','c' returns all elements EXCEPT those with class 'c'
- 'persist' - persist figure components information, allowing much faster results for subsequent invocations
- 'print' - display all java elements in a hierarchical list
Note1: optional PropValue of element index or handle to java container
Note2: normally this option would be placed last, after all filtering is complete.
- 'list' - same as 'print'

- handles - list of handles to java elements
- levels - list of corresponding hierarchy level of the java elements (top=0)
- parentIds - list of indexes (in unfiltered handles) of the parent container of the corresponding java element
- listing - results of 'print'/'list' options (empty if 'print'/'list' were unspecified)

Sample usage:
>> hButton = uicontrol('string','click me');
>> jButton = findjobj(hButton,'nomenu'); % or: jButton = findjobj('property',{'Text','click me'});
>> jButton.setFlyOverAppearance(1);
>> jButton.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
>> set(jButton,'FocusGainedCallback',@myMatlabFunction); % some 30 callback points available...
>> jButton.get; % list all changeable properties...
>> hEditbox = uicontrol('style',edit');
>> jEditbox = findjobj(hEditbox,'nomenu');
>> jEditbox.setCaretColor(;
>> jEditbox.KeyTypedCallback = @myCallbackFunc; % many more callbacks where this came from...
>> jEdit.requestFocus;
(Many more examples in the utility's help section)

Known issues/limitations:
- Cannot currently process multiple container objects - just one at a time
- Initial processing is a bit slow when the figure is laden with many UI components (so better use 'persist')
- Passing a container Matlab handle is currently found by position+size: should find a better way to do this
- Labels have a write-only text property in java, so can't be found using 'property',{'Text','string'} notation

Technical description:

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)

See also:
java, handle, findobj, findall

Cite As

Yair Altman (2021). findjobj - find java handles of Matlab graphic objects (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (202)



@Daniel use the findjobj_fast directly or better, use the callback of changing value from the editbox itself, it's a lot faster and easy to implement.

Daniel Melendrez

Thank you, Yair for this amazing set of functions. They are amazingly implemented and you basically saved my day. I am using Matlab 2019a with a complex GUI made in GUIDE. I was looking for a solution to dynamically analise the input string from an editbox.
I just want to point out that using the 'nomenu' option hinders the performance of findjobj when it is supposed to improve it (?). Am I missing something?. When adding the 'nomenu' parameter, I get the result I am looking for in ~800ms while after removing it (using no input parameters) I get a response in ~20ms. As expected, using findjobj_fast returns the result from an editbox in 8ms!

In short, this is slower:

function editboxValue_ButtonDownFcn(hObject, eventdata, handles)
editboxValueValue_Obj = findjobj_fast(handles.editboxValue);
editboxString = get(editboxValueValue_Obj , 'Text');
fprintf('Entered string: %s\n', editboxString )
guidata(hObject, handles)

--> object and string found in 8ms

than this:

function editboxValue_ButtonDownFcn(hObject, eventdata, handles)
editboxValueValue_Obj = findjobj_fast(handles.editboxValue, 'nomenu');
editboxString = get(editboxValueValue_Obj , 'Text');
fprintf('Entered string: %s\n', editboxString )
guidata(hObject, handles)

--> object and string found in ~800ms

Daniel Melendrez

Adam Danz

This submission has been helpful in so many ways and I really appreciate the time put into keeping it up to date. Just an FYI to other users, the JavaFrame property and javacomponent function used in this submission will no longer be supported by Matlab in future releases. More info:

Will Hirsch

MATLAB R2019b changes the ID of the warning MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame to MATLAB:ui:javaframe:PropertyToBeRemoved so the warning suppression in this function needs updating, though the functionality itself seems still to work fine!

Samuel Nadell

Thanks for the update, Yair! The latest version (7/3/19) of findjobj appears to fix the problem I was having with the 9/21/18 version in MATLAB R2018b/R2019a.

Joe Gibbs

Fantastic tool! Many thanks for creating it and keeping it up to date.

Leopoldo Brasil

Boyd Tolton

@Yair - I too don't think the problem is with findjobj. Unfortunately Mathworks technical support have decided they won't look into it.

Yair Altman

@Boyd - I do not believe the problem is in findjobj, but in any case you have a simple alternative for labels:

Boyd Tolton

I have been using this function to let me change the background of a uicontrol to transparent (function below). Upon updating to 2019a, my code started to crash due to a memory leak (it worked fine in 2018b and previous versions of Matlab). I have been back and forth many times with tech support, and have provided them with a simple version of the code which demonstrates the memory leak. Tech support has told me that they believe the problem is in findjobj, but that since it is 3rd party code they won't support it. I am very unhappy with this answer and am continuing to push back, but so far no luck.

function h = transparentUIcontrol(varargin)
% Creates a uicontrol with transparent background
h = uicontrol(varargin{:});
jLabel = findjobj(h);
if isfield(jLabel,'BorderPainted')
jLabel.BorderPainted = false;

Dr Fred

Paul Macey

Thank you for this - and it works with 2019a. (Version 1.47 had errors).

Giuseppe Fidelibus

Regarding my previous post, I found a workaround:

1. create a "dummy" figure where to parent the uitable
2. grab its Java handles and store them in a property
3. change the uitable parent to "TabPanel"
4. delete the dummy figure

I still cannot understand why the tool doesn't work if there is a "TabPanel" in the parenting tree of the uitable, though...

Giuseppe Fidelibus

I was looking for Java Handles underneath a uitable. It has always worked properly, until when I added a component of the GUI Layout Toolbox, in particular "TabPanel". It is now one of the grand-grand-grand(...)parents of my uitable: findjobj is not able to get my Java Handles anymore. I also tried to give findjobj the ancestor figure of my uitable as input, using the option "class" (findjobj(figureAncestor, '-nomenu', 'class', 'UITablePeer') , but nothing happens. I found out that if I get the property "JavaFrame" from each of the grandparents of my uitable, the only not-empty result I get is when I interrogate the "TabPanel" object (which makes sense!): I was wondering if it is somehow related to the misfunctioning of the tool...

Kosuke Hamaguchi

E Zakreski

Mariano Aránguez

@Yair - You're right. If instead of the optional GUI handle, I use the figure and search by 'class' parameter, then it works:
jHandle = findjobj(h,'class','JTabbedPane')
...although more slowly... Fortunately, the speed is fixed adding the 'nomenu' parameter.
jHandle = findjobj(h,'class','JTabbedPane','nomenu')

Thanks a lot!

Yair Altman

@Mariano - findjobj uses among other things the pixel position and size to find the underlying Java object and this may change with the display resolution. Instead, you can try to use the 'class' parameter to search for the object, and this should be independent of the resolution.

Mariano Aránguez

Amazing tool!

Just a weird issue that I've come across with the following code (Matlab 2018b):
h = figure;
tabgroup = uitabgroup(h);
tab1 = uitab(tabgroup, 'Title','tab1');
tab2 = uitab(tabgroup, 'Title','tab2');
jHandle = findjobj(tabgroup,'class','JTabbedPane')

If I set the screen display settings in Windows (7 and 10) with 125% size, then I get:
jHandle =
1x0 empty handle

But if I set the screen display settings with 100% size, then fine... I get what I expected:
jHandle =



Yair Altman

@Eddie - thanks for your note, I incorporated your workaround in the latest version that I just uploaded.

@Jeevith - MathWorks changed the internal implementation of uitables so findjobj now only reports the table's wrapper scroll-pane handle. You can get the uitable peer via hScrollpane.getViewport.getView. Alternatively, you can still get the peer handle directly if you search for it in its containing figure (not directly via the uitable handle): findjobj(hTable.Parent, 'class','uitablepeer')


Findjobj no longer finds java handle of uicontrol for 2018b. However I found a fix. Replace line 3399 -

It appears that setting Tooltip property no longer set the ToolTipText in its Java Container. But setting TooltipString does.

Jeevith Hanumanthaiah

Hello Mathworks,

findjobj function is not working properly for the property 'UITablePeer' but it is working fine for other properties and for details please refer the below code.
value = findjobj(handles, '-nomenu', 'class', 'UITablePeer')

The value that is returned by function findjobj for the property 'UITablePeer' is not correct.
We are using the latest version of findjobj.m file and the matlab version which we are using in 2017b.
It is working fine in matlab version 2011b but not in matlab version 2017b.
Can you please provide the solution so as to fix the issue.

Thank you.

Vyshakh Pv

Thanks a lot, it works. findjobj???

Leopoldo Brasil

Yair Altman

@Hanzala - findjobj only works with Java-based windows (created using GUIDE or the figure function). AppDesigner (and the uifigure function) creates a Java-script window that is not, and will never be, supported by findjobj.

Hanzala Sharif

Hello. This tool works as mentioned for normal GUIDE components but i've been trying to implement this in an app designer app. The returned handles are always empty. Has this been tested with app designer as yet?

Liu Yang

Excellent tool

Youngjoo Kim

thnaks, it's really useful to me. i want to move the position of scrollbar where i want automatically, i will share this code jScrollpane = findjobj(handles.tagTable_TargetList);
jScroll = jScrollpane.getComponent(0);
scrollMax = jScrollpane.getVerticalScrollBar.getMaximum;
scrollValue = floor(scrollMax * ((row_index-1)/row));

Timo Dörsam

Lorenzo C.

Really useful, i used it to bind right click on list views in my sessionmanager project.

Andrew Janke

This is great! Very useful, both as a tool, and an example of building tree-based GUIs. Thanks for sharing this.

Nicolai Kern

Stefan Grandl

Richard Fletcher

Is this expected to work with uifigure and all other associated appdesigner components?

jilong shi

Joseph Wagster IV

With an earlier version, had the same error as CalinV:
Error @ jScrollpopup.getViewport.getView --> "Undefined function 'getViewport' for input arguments of type 'handle.handle'."

Seems to be fixed in new version and was likely due to new drawing order/delay. Great work!

Paolo Inglese

Yongjun Wang

very good ui

Michele Catalano

Same error as for CalinV. Thannx for the fantastic utility!


Great function! I have a question regarding changing the Background and Foreground color of popupmenu items when hovering the mouse over them (default is that clasic blue). How can I do that ?
I tried with the folowing code lines (which worked for listbox and table classes) with no success:
function popupmenu_Callback(hObject, eventdata, handles)
jScrollpopup = findjobj(hObject);
jPopupmenu = jScrollpopup.getViewport.getView;
Error @ jScrollpopup.getViewport.getView --> "Undefined function 'getViewport' for input arguments of type 'handle.handle'."

Xiangrui Li

I really hope Matlab can expose the java handle of UI object for advanced programming. Then we don't need this complicated trick. Until then this is a great tool!

Xiangrui Li

Martin Sundqvist

Fantastic utility. With the previous version, I was using the following code to change the widths of the first column of cells (the row names) of a table, to 100 pixels

jTable = findjobj(handles.MyTable)
rowHeaderViewport = jTable.getComponent(4)
rowHeader = rowHeaderViewport.getComponent(0) ;
rowHeaderViewport.setPreferredSize(java.awt.Dimension(100,0)) ; % 100 = width in pixels
height = rowHeader.getHeight ;
rowHeader.setPreferredSize(java.awt.Dimension(100,height)) ;
rowHeader.setSize(100, height) ;

In the new version this returns an error at the third line:

Java exception occurred:
java.lang.ArrayIndexOutOfBoundsException: No such child: 0
at java.awt.Container.getComponent(Unknown Source)

Martin Lehmann

I found two reasons why the latest version is much slower than before. Both lie within findjobj_fast:
1) pause(0.001) is really inaccurate and actually pauses for 0.01 secs or more on my machine. This is a known issue with pause.
2) in findTooltipIn, the getToolTipText method takes ages, especially because it is called 100 times until the code switches to the legacy method.
Both times it can't find an object via the fast method and my code wastes 14secs (for 6 ui elements to inspect) here.

My quick workaround is to reduce the counter to 10 (line 3390) and the pause to 0.01 (line 3395). The solution is probably to rethink the approach or decide earlier that the fast method isn't finding anything.


I extensively use finjobj, which is a wonderful tool. But unfortunately, I had to revert to version 2014-01-04 because every one of the newest versions breaks something in my code :

2016-04-11 version: some of my tooltips get replaced by '!@#$%^&*'

2016-04-14 version: generates errors in the command line

2016-04-19 version: fixes the tooltip and errors from the two previous versions, but takes about twice the time to execute (8 s instead of ~4 s for my GUI initialization code to execute)

By the way I'm using R2011b.

Elias Brohammer



This is a great function that we use all the time for an interactive mapping GUI. We were glad to have a speed update. While it really improved things when using the newer versions of Mat Lab, our GUI took about 10 times longer to open in MatLab 2012 which many of our users have (faster map graphics than 2014b).

Using the profiler I tracked the issue to the fact that findTooltipIn is called 1100 times per call to findjobj. jControl is always empty so the while loop executes 100 times in findjobj_fast. Once in findTooltipIn it calls itself 54 times (in our application) all for nought. Then since jControl is still empty it executes the old logic. I have solved the issue for now in our code by just adding a version test before going down this route.


Thanks Yair! The latest update works great

Yair Altman

@MikeLab - I just uploaded a new version that should fix the problem that you see on R2013a (or any other Matlab release older than R2014b)


This is very useful!

Is there a way to access an older version of findjobj?

The current version works well for me with Matlab 2015a, but on PCs with Matlab 2013a, I get an error.

Here is an example:

function GetJTableTest

f = figure;
data = rand(3);
colnames = {'X-Data', 'Y-Data', 'Z-Data'};
t = uitable(f, 'Data', data, 'ColumnName', colnames, ...
'Position', [20 20 460 350]);
jscroll = findjobj(t);


Command Line Output:
>> GetUITable
findjobj: Number of elements in right hand side does not match number required by left hand

Error in findjobj (line 278)
handles (dataLen+1:end) = [];

Error in GetUITable (line 8)
jscroll = findjobj(t);

410 rethrow(err);

Additional Information: The scope of variable 'handles' spans multiple functions.

Michael Cappello

I use it ALL THE TIME. Love it!

William Lu

Much appreciate the update! Significantly faster. I see about a x4 improvement in my functions that use findjobj.

However, it was not a simple drop and place of the new findjobj. I set the parent figure of the component to be invisible however findjobj would not find all the components. The previous findjobj was able to.

I was able to workaround this by moving the figure off screen and letting findjobj find the components and move it back screen.

Marco Ruijken

Hi Yair,

I don't see much improvement in speed for a GUI application with about 25 uicontrols.

Furthermore, the tooltipstring of my uitable keeps displaying strange characters.


S Jeriniaina


Luke Plausin

Charles Godreau

Hi Yair, great work on this findjobj function! Been using it for our GUIs and it worked great. One of my colleague updated to both Matlab R2015b and Windows 10. Now the findjobj does not return anything from a uitable.

I thought it could be related to the new Matlab version, so I tried it on my windows 7 machine and I get the following from a simple call to a uitable in R2015b:

>> hTable = uitable;
>> jScroll = findjobj(hTable)

jScroll =

On the windows 10 machine I get :
>> hTable = uitable;
>> jScroll = findjobj(hTable)

jScroll =

handle: 1-by-0

The java object is not recovered...

Do you think this is related to the OS? Are there any differences in the way Matlab would handle java objects between Windows 7 and 10?

Thanks in advance,

Martin Sundqvist

Excellent utility. FWIW I had some problems in a GUIDE gui where I called findjobj several times in my opening function, as it caused the gui to loose keyboard focus. This was solved by calling x = findjobj(gcf) in the OutputFcn. There was no need to use 'x', simply pointing findjobj to the gcf did the job.

Martin Sundqvist


Thanks Yair for fighting for a better Matlab :-)
I've faced a problem with findjobj which makes it hard to use.
findjobj doesn't find objects in inactive tabs. Is there a workaround? For now, I select the tabs before drawing them, but this is not really fail-safe.

Thanks a lot,




Ilya Belevich

Michael Pitts



@Yair — I found a small bug when trying to inspect the root object:

>> findjobj(groot)

findjobj: The following error occurred converting from matlab.ui.Root to handle.handle:
Conversion to handle.handle from matlab.ui.Root is not possible

Error in findjobj/traverseContainer (line 505)
handles(thisIdx) = handle(jcontainer,'callbackproperties');

Error in findjobj (line 259)

Strangely enough, when trying an "old-school" approach, it doesn't err:

>> findjobj(0)

ans =

handle: 1-by-1144

And the main node is the Main Desktop Frame "com.mathworks.mde.desk.MLMainFrame".

Besides that, FindJObj is an excellent very useful utility. Keep up the good work!

Luis Camilo

Sebastian D'Amico


Aha - I was unaware that I could use the clear command to reset the persistent variable - thanks for that info.

Yair Altman

@Gary - I think your solution is not good: findjobj already clears the persistent handles when it detects a different container than the previous one.

If you already know that the container's contents (rather than its handle) have changed, all you need to do to clear the persistent handles is to call clear('findjobj') at that point. Subsequent calls to findjobj will see cleared persistent vars and will recompute them.

If you like findjobj, please rate it.


Yair - thank you very much for this fix. I'd like to make another recommendation. It has been valuable for me to use 'persist', but then to erase the persistent catalog when I know the container has changed contents. I handled this by adding "pContainer = [];" after "if isempty(container)" at around line 170; I'm not sure if this would mess up other users or if you want a specific argument value that would erase the container.
- gary

Yair Altman

@David & @Gary - the latest version of FindJObj addresses this issue and differentiates between overlapping controls, without having to use the workaround suggested by David.

David Sandford

Hi Paul,

I've found a solution to your problem, but it's not ideal as it requires running the findjobj twice to rescan all objects.

% findjobj test script
tgrp = uitabgroup('Parent',hWnd);
tab1 = uitab('Parent',tgrp,'Title','tab1');
tab2 = uitab('Parent',tgrp,'Title','tab2');
a = findjobj(t1,'-nomenu','-property',{'Name','uitable1'},'-property',{'UIClassID','ScrollPaneUI'});
b = findjobj(t2,'-nomenu','-property',{'Name','uitable2'},'-property',{'UIClassID','ScrollPaneUI'});


Hi Yair - My code snippet replaced my earlier comment. The 'aliasing' problem is that findjobj cannot distinguish two different tables placed in the same position in two different tabs.


Here is the test code to demonstrate the aliasing problem:
% findjobj test script
tgrp = uitabgroup('Parent',hWnd);
tab1 = uitab('Parent',tgrp,'Title','tab1');
tab2 = uitab('Parent',tgrp,'Title','tab2');

Yair Altman

Matlab does not actually render the Java component until it is displayed at least once. So until that time, findjobj will return empty.

In R2014b the entire underlying graphics rendering engine has changed (so-called HG2) so it is not surprising that things that worked well in 14a need to be adapted to work in 14b. In fact, I find it a small miracle that findjobj still works well [most of the time] in 14b... In your case, you can simply activate the tabs programmatically, and call drawnow(), and this should solve your issue.

Bradley Steel

I had a similar error to Sneha, coming when a findjobj call that worked in 2014a returned an empty results in 2014b.

It my case, I was creating a uitable on a TabPanel from the GUILayoutToolbox. findjobj was not able to find the uitable after creation. It was able to find it after I changed the active tab to be that containing the uitable.

Not sure if that helps - or exactly why findjobj cannot find the object before the tab is activated.



I am also getting an error using this function in the 2014b version. "No appropriate method, property, or field getViewport for class handle.handle."

Yair Altman

Zoé - download the latest version, it should work ok on R2014b.


Unfortunately, findjobj not seem to work in R2014b:

findjobj: Error using
The name 'NodeExpandedCallback' is not an accessible property for an
instance of class 'com.mathworks.hg.peer.UITreePeer'.

Error in findjobj/presentObjectTree (line 1524)
set(tree_hh, 'NodeExpandedCallback', {@nodeExpanded, tree_h});

Error in findjobj (line 303)


Dear Yair,

Somehow the code seems to not always work when I run .m file. I built a GUI with a pushbutton and a edit box. If i press the pushbutton i can chose data such as .txt and .csv files and write the first 20 lines in the edit box. However, sometimes, when loding the same files (what I get when I load them is also identical, so it should not be my data loading function), there is a horizonal scrollbar and sometimes there is not. The follwoing I wrote in the GUI opening function:

jScrollPane = findjobj(handles.edit1);
set(jScrollPane,'VerticalScrollBarPolicy',20); jScrollPane.setHorizontalScrollBarPolicy(30);
jViewPort = jScrollPane.getViewport;
jEditbox = jViewPort.getComponent(0);

Do you have any idea? Is there a bug or is it just me (more likely XD)




I use findjobj to add icon on multiples Button and use Progressbar...but when i run the Gui, it open and close ( flasjing)at each "findobject" call.

then works fine... any idea what's going on ?
jButton = java(findjobj(handles.Apply, 'nomenu'));
myIcon = fullfile(currentDir,'/icons/apply.png');


How to put matlab on steroids! Very useful to have more control of your GUI.


Very useful and very cool

Yair Altman

Sebastian - perhaps the nested panels cause the reported pixel position of the mtable to be slightly different than the jtable, causing the jtable not to be found at the expected position/size. This would not surprise me since each uipanel ads a 1-2 pixel border on each side so the more uipanels that you nest the larger the probability of a position mismatch.



Dear Yair;
Sorry about the confusion - my comments doesn't seem to have posted correctly.
I have used your excelent findobj on many occasions but today discovered a strange behaviour. When nesting many panels inside each, findjobj does not seem to be able to find that underlying java table handle. As a simple example:

subpanel1 = uipanel('Parent', gcf, 'units','normalized','Position',[0 0 1 1]);
subpanel2 = uipanel('Parent', subpanel1, 'units','normalized','Position',[0 0 1 1]);
subpanel3 = uipanel('Parent', subpanel2, 'units','normalized','Position',[0 0 1 1]);
subpanel4 = uipanel('Parent', subpanel3, 'units','normalized','Position',[0 0 1 1]);

% This works correctly
mTable= uitable('Parent',subpanel3,'Units','normalized',...
'Position',[0.02 0.14 0.96 0.84]);

jHandle = findjobj(mTable)

% This does not work - findjobj returns empty
mTable2= uitable('Parent',subpanel4,'Units','normalized',...
'Position',[0.02 0.14 0.96 0.84]);

jHandle2 = findjobj(mTable2)

Any thoughts?
Best regards



Dear Yair;
Adding to my previous comment, I have noticed that findjobj(gcf,'class','uitable') correctly finds the handle also in the later case. The trouble with this in my case is that I have several tables in the GUI and this returns a vector of all tables and all I have found no way to distinguish between these to extract the particular one that I want.
Best Regards

Andrew Bytheway

Yair - I've found one issue that should be resolved:

If after calling findjobj with the "persist" option the main GUI window is moved, then subsequent calls to findjobj will fail to return the object handle. This is because the container (or pContainer) is one of the persisted variables, and the processPositionArgs function uses container.getX and container.getY to filter the java objects.

To make matters worse, a subsequent call to findjobj without the "persist" argument does not disable persistence. The way I read the code, the only way to force findjobj to recalculate all of the positions is to call it first on a separate figure with the "persist" argument and then on the desired figure without the "persist" argument. (I haven't tested this so I could be wrong). I think this could be fixed fairly easily with a few code changes around line 237.

The complete fix will be a little more involved though.

It looks like others (i.e. Kesh Ikuma) have had similar issues. I've rated this as a 4 for an awesome tool. This would be a 5 if the "persist" option could be made to reset if the figure is moved or resized.

Daniel Shub

Kesh Ikuma

Yair - What do you think of adding a flag 'repersist' (or whatever name you think best describes the feature) to rescan the container to update the persistent data?

I run into a problem by calling findjobj(...,'persist') multiple times as the GUI is constructed. I've modified line 240 to

"if isequal(pContainer,container) && ~paramSupplied(varargin,'persist')"

for the time being but would love to have an official feature to account for this case.

Thanks, Kesh

Yair Altman

@Dan - maybe, it should be simple enough to test

Dan K

Thanks for the feedback.... Would it work if I were to undock the figure, find the object, and then re-dock? Or would the act of re-docking the figure change the handles?

Yair Altman

@Dan K - This is correct: findjobj is not expected to work for docked figures since the Java components hierarchy in this case is entirely different - a docked figure is merely an internal panel within the Desktop window, not a standalone Frame/window as in the undocked case.

Maybe one day I'll upload a fix for this, but I don't expect it in the near term.

Dan K

Thank you for the great utility. One item I noticed. It doesn't work with figures that are docked. If I use:

hButton = uicontrol('string','click me');
jButton = findjobj(hButton,'nomenu');

On an undocked figure, it finds the handle, but if I dock the figure, it returns an empty matrix. Thoughts?


Thank you Yair!
By using this function I was able to work around a problem in some code I am writing, that has been bugging me for days!

Yair Altman

@Satwik - you can tell findjobj to search by position and/or class, not just size - read the findjobj help.

In my experience, the position sometimes changes by a few pixels on different systems but the size remains the same - it's odd that you find that size changes.


First off, thanks for all the great submissions. They greatly extend the utility of MATLAB GUIs.

I ran into a strange problem using findjobj, which has its origin upstream, but comes from findjobj finding elements by position.

On a GUI created by a colleague, findjobj works perfectly on windows machines, but fails intermittently on linux.

I have traced this back to the fact that the size detected seems to change sometimes in linux, despite the fact that these are hardcoded in the gui. For example the height component of contentSize in getRootPanel changes and this causes the baseDeltas for the height to go out of the accepted range.

I realize this is likely not an issue with findjobj, but I was wondering if you had run into this issue before and/or could offer some suggestions on how to ensure reliable detection of gui size.


Ricardo V. R.

Ok thanks, that was it.

If I change any uicontrol's (edit box) properties after I've changed its pointer (I have done a calendar of which days are edit boxes and I want its hover pointer set to default arrow and not |), it seems to malfunction the setCursor.

What I want to know is if an uicontrol's propeties are being constantly changed do their setCursor property reset to default or I just have to change it once.
Summing up, what I want is to change a calendar's edit boxes days pointer to the default arrow.

Thank you.

Yair Altman

Ricardo - the button is probably not visible at the time that you call findjobj. It has to be visible to work

Ricardo V. R.

First of all, thank you for all your contributions. I've read you a lot.

I can't get the fidjobj working on R2012b, it returns me always []


>> hButton = uicontrol('string', 'Hello');
jButton = findjobj(hButton);

jButton =



It works now. I had to re-set the callback function after b = findjobj(handle2).
It seems that the second call to findjobj, deactivates the callbacks for object a.

Thanks for your help.

Yair Altman

There is no real reason that it should not work. Perhaps one of the tables was not visible at the time that findjobj() was called. place a breakpoint on both lines to check whether this is in fact the case.


Thanks for your answer. I don't mean vectorization.

I have problems using
a = findjobj(handle1)
b = findjobj(handle2)

Both calls were made from different functions, handle1 and handle2 are different tables in the same GUI. call_1 XOR call_2 works fine. Any suggestions?

Yair Altman

@ismirbrille - findjobj only works on a single component at a time, it is not vectorized. To get the underlying Java objects of multiple Matlab controls you would need to call findjobj separately for each of the controls.


@Yair Altman - Thank you for this code, very useful, good job!
Do you currently work at a version which supports multiple container objects?
I have to use 2 tables with java functionality at a time.

Martin Lechner

Sad, that Matlab doesn't support modern GUI development.
Thanks for the great work to overcome the limitations!

Martin Lechner


Ok, Thank you!!!! Yair Altman

Yair Altman

@Katana13 - Java customizations are not saved in FIG files. See here for a discussion and workaround:


Extremely useful toolbox for creating GUIs. I don't know if it's a limitation (Matlab R2012a). Example:
h = figure('Menubar','none', 'Toolbar','none','Tag','figure');
str = ' je suis vraiment le plus beau de la planete terrrer de la foucv oeufe fz ozfz efz fvousf zefzf ouvzfz ozfz fouz fz fzo ufzf zouz fozufozf uzo fzoufzo fuziofz fzofiuzfoiz fouzfo ';
hEdit = uicontrol('Parent',h, 'Style','edit', 'FontSize',9, ...
'Min',0, 'Max',2, 'HorizontalAlignment','left', ...
'Units','normalized', 'Position',[0 0 1 1], ...

%# enable horizontal scrolling
jEdit = findjobj(hEdit);
jEditbox = jEdit.getViewport().getComponent(0);
jEditbox.setWrapping(false); %# turn off word-wrapping
jEditbox.setEditable(false); %# non-editable
set(jEdit,'HorizontalScrollBarPolicy',30); %# HORIZONTAL_SCROLLBAR_AS_NEEDED

%# maintain horizontal scrollbar policy which reverts back on component resize
hjEdit = handle(jEdit,'CallbackProperties');
set(hjEdit, 'ComponentResizedCallback','set(gcbo,''HorizontalScrollBarPolicy'',30)')


No problem, if you directly run the script (horizontal + vertical scrollbar available). But if you launch the saved file : 'test.fig', the horizontal scrollbar becomes unavailable.


Raz Shimoni

Raz Shimoni

Extremely useful function that helped me alot. Just excellent!

Fred Holt

Thanks for the support!

I used findjobj to update a table position, and it works well, but there are some rendering artifacts as a result of the update - hopefully seen here: .
Apologies, as I am not too familiar with java, but a simple drawnow doesn't seem to help.

Yair Altman

@Georgios - the control must be visible for findjobj to work. You can make the figure visible in the OpenFcn using the commands
set(hObject,'Visible','on'); drawnow;

If you don't want the figure to physically appear onscreen, you can set its position to [-300,-300,200,200] or some other off-screen location. The figure will become visible but hidden... You can later move it to your screen center in the OutputFcn.

Voulgarakis Georgios

Hallo and congrats for the excellent code!

My issue is the following:
I need to use the findjobj, before the uicontrol is properly rendered.
Is there a way to achieve this?

(I need to set some attributes of the uicotnrol, in the OpenFcn function of the GUI.) Which means that the uicontrols are not yet rendered.

Yair Altman

@Echidna - findjobj works out-of-the-box and does not require any additional installation or file, including in deployed (compiled) apps. So I am 99.99% certain that the problem is in your code. It could be due to one of several possibilities:

1) perhaps your editbox has not become visible onscreen long enough before your call to findjobj. Findjobj must have the control visible before it can find its underlying Java component. Place calls to pause(0.1) and drawnow before your call to findjobj, to ensure that this is indeed so.

2) maybe your callback function became invalid for some reason. For example, if you modify the editbox from multi-line to single-line or other similar changes, then the underlying Java control may have changed, forcing you to re-set your callback

3) maybe your update callback is being called but runs into a bug when updating the listbox for some reason. Place debug printouts in your callback to check this.


This code works great when I run my GUI directly in Matlab BUT when I compile it into an executable using deploytool, it does not always work. More specifically it works the first time I change the text in the edit box, sometimes the second time but somewhere thereafter (always at a different point), it does not seem to work anymore (i.e. no update of my listbox when I type in the edit-field and some other strange stuff sometimes happens as freezing of the list box, not finding the text string even though I know it is there and such).

Is this a known bug and how can I solve this? Is there another file that I need to include in the "Shared resources and helper files" section besides the findjobj.m file which I of course have included?

Yair Altman

@Peter - as far as I could test, the latest findjobj works correctly on R2012b. try running your two lines in a new figure and see for yourself. Perhaps in your specific GUI findjobj cannot find the slider control for some reason. One possible explanation is that the uicontrol is not fully rendered (displayed) when findjobj is being run. In this case, placing a short pause(0.05) and drawnow(), might help. Also ensure that the slider is actually displayed onscreen (Visible=on, valid Position and Value).

Peter Corke

I've used this module successfully for many years, thanks.

With R2012b I've got problems:

jh = findjobj( slider, 'nomenu');
jh.AdjustmentValueChangedCallback = @(src,event)sliderCallbackFunc(src);

and the second line results in an error

Incorrect number of right hand side elements in dot name assignment. Missing [] around left hand side is a
likely cause.

Anybody else had related problems under R2012b.

Alexander Kosenkov

Alexander Kosenkov

Yair Altman

@Changshun Deng - I believe that the latest version of FindJObj that I uploaded yesterday solves this issue

Changshun Deng

Hi, I run this programe findjobj(jEditor) as
I can not get the objects of editor.
an error: ??? findjobj: There is no 'UserData' property in the 'javax.swing.JTable$1' class.

my matlab version is: MATLAB Version 7.4

Martin Lechner

Yair Altman

@Ward - thanks - I believe that you may be right. This has no effect unless there are several overlapping/similar results in the filtering process, which is very rare. But in such rare cases, your fix would solve a problem of returning both the parent and the child handles.


On lines 646-649 you discard the first if in the original handles the first is the parent of second. Is this correct after Args processing or should the first line be

if length(foundIdx) > 1 && isequal(handles(foundIdx(1)).java, handles(foundIdx(2)).getParent)

David Thompson

This is a very cool tool, but I'm running into the same problem that Michael had - if I compile the code, I get a metric ton of "file is empty" messages. Everything works fine, it just gets in the way of other things I'd like to use the output window for. Any hope of an update to address this?

Yair Altman

@HaveF - you don't need to use the 'nomenu' parameter when you specify an input handle such as hButton.

I cannot reproduce any of the issues that you report. Perhaps try to download the latest version of the utilities.

Try adding a call to drawnow and/or pause(0.1) before you call findjobj. Also, ensure that the control is actually visible (findjobj can only detect visible components).


seems lost something...
When I try findjobj, something strange on my machine.
>> hButton = uicontrol('string','click me'); jButton = findjobj('property',{'Text','click me'});
it's all right as I expected.
>> hButton = uicontrol('string','click me'); jButton = findjobj(hButton,'nomenu')
just return *ans = <1x0>*

and another thing, I am a big fun of yours.
I use setPrompt before, but when I try findjobj, my prompt disappear.
just like this:

[18:57:11]temp_proj>> hButton = uicontrol('string','click me');
[18:57:16]temp_proj>> jButton = findjobj('property',{'Text','click me'});


and another thing, I am a big fun of yours.
I use setPrompt before, but when I try findjobj, my prompt disappear.
just like this:

[18:57:11]temp_proj>> hButton = uicontrol('string','click me');
[18:57:16]temp_proj>> jButton = findjobj('property',{'Text','click me'});

Nik F



the above code works - often ;)
sometimes it throws:

No appropriate method, property, or field getViewport for class handle.handle.

-> class handle.handle => haha

how can i assure findjobj found the table?

currently i retry on failure:


function setTableSelectedCellColor(table)

jUIScrollPane = findjobj(table, 'nomenu');
jUITable = jUIScrollPane.getViewport.getView;

end %function

end code


I use it to avoid selection induced color change for a table with white background:


% create the table
table = uitable( ...
'Parent', layout,...
'ColumnWidth', {100, 150}, ...
'ColumnName', {tableTitle}, ...
'RowName', [], ...
'ColumnFormat', {'char', selectionList}, ...
'ColumnEditable', [false, true],...
'Data', tableData, ...
'CellEditCallback', @selectionChanged);

% workarount to avoid seletion induced color change
jUIScrollPane = findjobj(table);
jUITable = jUIScrollPane.getViewport.getView;

end code

is there a way to make the findjobj command faster?


Yair Altman

@Evzen - for some reason, you got the handle of a uitable rather than the editbox, and of course you cannot set the page URL for uitables...

Perhaps your uitable resides at the same pixel position as the editbox?

Try to place a breakpoint on the line following the call to findjobj to determine exactly which object it found.

More information on setting rich editbox contents can be found here:

Evzen Brusle

Awsome utility. Thanks for sharing, but I have a little problem and i dont resolve it. I use a code from your webpage, but it give me this error with method setPage:

No appropriate method, property, or field setPage for class

hEditbox = uicontrol('style','edit', 'max',5);

jScrollPane = findjobj(hEditbox);
jViewPort = jScrollPane.getViewport;
jEditbox = jViewPort.getComponent(0);

Yair Altman

@Sean - you don't need findjobj to access specific toolbar buttons - you can use the built-in findall function, as explained here:

Andrew Bytheway

This is an awesome tool. Thanks for your sharing your work Yair.

Sean Larkin

I'm trying to use findjobj to get the java handle for a toolbar uitogglebutton. It does not find the handles for the button. When I call the function like this:

it finds the toolbar button. Why is this and is there a way I can modify findjobj to directly find toolbar buttons?


Works super! Nevertheless, when I compile this line:
jScrollPane = findjobj(handles.editBox)
and I execute the code, I get many times the message 'File is empty' in the command line. Anyway, the code works nevertheless!? Any ideas?

Best regards!

PS: I use your tool to extract selected text from an edit box.

Emad Hasan

Finally got it to work, thanks a lot for the updates!


Hi Guys,

I have written the following code in _OpeningFcn(because I have used GUIDE!),

set(jb(2), 'MousePressedCallback', @UpVertTest);
guidata(hObject, handles);

Up to here everything works fine,

But at the end of my m file where I define the related function(UpVertTest) I have problem,
I want to have access to normal handles and do some changes, But I get this error:

??? Undefined function or method 'toDouble' for input arguments of type 'java.awt.Dimension'.

Error in ==> opaque.double at 80
dbl = toDouble(opaque_array(1));

Error in ==> guidata at 85
if isscalar(h) && ishghandle(h)

Error in ==> RatRobot_GUI4>UpVertTest at 523

this is the code I have written:

function UpVertTest(src, evnt)
% trying to access to handles

% set new initial value in GUI

I think there is something wrong with my function definition,
any ideas?

Oscar Hartogensis

I used the findjobj-function as described at to disable text-wrapping and display a horizontal scroll-bar in a GUI edit-box.
Many thanks for this fabulous tool. It works like a charm.


after further testing, following the use of findjobj, from time to time i get the following errors:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.text.BoxView.calculateMinorAxisRequirements(
at javax.swing.text.html.BlockView.calculateMinorAxisRequirements(
at javax.swing.text.BoxView.checkRequests(
at javax.swing.text.BoxView.getPreferredSpan(
at javax.swing.text.html.BlockView.getPreferredSpan(
at javax.swing.plaf.basic.BasicTextUI$RootView.getPreferredSpan(
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(
at javax.swing.JComponent.getPreferredSize(
at javax.swing.JEditorPane.getPreferredSize(
at com.mathworks.hg.peer.EditTextPeer$hgTextEditMultiline.getPreferredSize(
at javax.swing.ScrollPaneLayout.layoutContainer(
at java.awt.Container.layout(
at java.awt.Container.doLayout(
at java.awt.Container.validateTree(
at java.awt.Container.validate(
at javax.swing.RepaintManager.validateInvalidComponents(
at javax.swing.SystemEventQueueUtilities$
at java.awt.event.InvocationEvent.dispatch(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(

is there a workaround?


that does make sense. thank you for clarifying that.

Yair Altman

Jveer - FindJObj *cannot* work in the GUIDE-created *_OpeningFcn because the figure is not yet visible at this time and so the Java components have still not rendered and therefore cannot be found.

Try placing your call to FindJObj *after* the figure has become visible and all the controls have completed rendering, for example by moving your FindJObj call to the *_OutputFcn function, hopefully after a call to drawnow to ensure that everything has completed rendering.


i'm sorry to report it still doesn't work. downloaded it today, tried it on r2009b and r2010a. frustratingly sometimes it works sometimes it doenst.

1) run from a script - it works
2) run from opening function of a GUI created using guide - doesn't work
3) run the script from #1 after #2 failed - it doesn't work!
4) reopen matlab and run #1 - works

very strange.

Yair Altman

Patrick, Emad & Jayveer - I have yesterday uploaded a new version of FindJObj that fixes the problem you have reported.

FYI, the problem occurred due to a slightly different implementation of the Java hierarchy for Matlab figure windows. The new code should work find on all the older Matlab 7 versions *IN ADDITION* to R2010a.

As always, I am very committed to fixing such utilities, to the best of my abilities, also in upcoming Matlab releases.


findjobj returns [] on r2010a !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

which makes the following tutorial useless!! - along with everything else on the website since they all depend on finjobj!

Kusa358 Figueredo

Emad Hasan

I have the same problem as Patrick.

I made a slider using GUIDE; its handle is hSlider.
I called jSlider = findjobj(hSlider);
I tried this with MATLAB 2007b, this worked very well, thank you.

Then I tried this with MATLAB 2009a, findjobj returned empty!
Actually, calling findjobj with any arguments all returned empty.

What did I do wrong?

Yair Altman

Dear Malcolm - Thanks for the feedback.

ApplicationData is a hidden property which is not shown by the property inspector used by FindJObj.

To see this information, simply select the relevant object in the FindJObj hierarchy tree and click the "Inspect object" button. This opens the UIInspect utility, which does display ApplicationData (if available) in UIInspect's bottom-right ("other properties") table.

If you need more control, you can always use FindJObj's "Export to workspace" button, and get the ApplicationData from the exported object handle.

Malcolm Lidierth

Superb tool Yair. Do you any plans to provide access to the application data areas of the objects e.g. from the context menu in the left-hand panel?

Alexander Kosenkov

That's simply amazing how deep inside could you get into Matlab internals! That's incredibily useful if one needs to bult-in matlab into Java application. Something like this should be definetely included into Builder JA



Oliver Woodford

Great function. The interactive display is a brilliant feature.

Patrick Tai

I made a slider using GUIDE; its handle is hSlider.
I called jSlider = findjobj(hSlider);
I tried this with MATLAB 2007b, this worked very well, thank you.

Then I tried this with MATLAB 2009a, findjobj returned empty!
Actually, calling findjobj with any arguments all returned empty.

What did I do wrong?

Saidul Hasnan

Why do I get this error whenever i tried findjobj;

??? findjobj: Undefined function or variable "jcb".

I have the latest version of findjobj file.


Jesse Hopkins

I've actually solved my problem. After reading this page:,
I tried changing the way I set the callbacks. Before, I set the callbacks directly on the java-object. However, when I used the handle() function and then set the callbacks the problem disappears.

In summary:

myHandle = handle(myJavaObject,'CallbackProperties');

Jesse Hopkins

I've been using this file for about a year now (great work Yair!), and a very weird issue has crept up now that I've upgraded from R2007b to R2008b.

What happens to me is that I have a few custom java-objects instantiated (they are a modified version of the java-swing table), with userdata and function callbacks associated with them via calls like: set(myTableObj,'MouseReleasedCallback',@callbackfcn);

After findjobj returns, all of the userdata and callbacks have been cleared out. I've stepped through findjobj line by line, and cannot find a culprit. In fact, when I get to the "return" line on 279, the userdata and function callbacks are still properly associated with the java-objects. However, once findjobj returns, all userdata and function callbacks of my java-objects are cleared to an empty matrix.

Any thoughts on this?

Yair Altman

@Leonardo - FindJObj does not enable modifying the displayed object hierarchy - perhaps I will add this feature in a future version. You need to update the hierarchy outside FindJObj and then click on the <Refresh Tree> button.

Leonardo Glavina

Great file! i just have one doubt using it: if I can chance the order of some structures. I have some check boxes and using 'tab' to select them is completely out of order, and using this function I found that it's following the specific order that is on the tree.

So, can I change the place of my tree's items?

thanks for the code


Great work, Yair! I have refferenced it in my spaces.
Only one suggestion: To be compatible with future versions of ML, the use of "JavaFrame" in your function should be avoid. The "JavaFrame" is a com.mathworks.hg.peer.FigurePeer Object, it can be easily obtained using a JAVA approach instead of the get(hfig,'JavaFrame'). For example, you can get if from the mde's Client.

Dennis Olly

ucd puri,

> but i did not understand how did you figured out
> AdjustmentValueChangedCallback attribute in line below

I just used findjobj itself:

hSlider = uicontrol('style','slider' );
findjobj( hSlider )


btw: did I mention findjobj is excellent !?

Matthias Höller

Awesome tool to find the underlying java objects of MATLAB objects! Works great!

Husam Aldahiyat

Zhang Yanxiang

Great work!




Sebastian Hölz

Another suggestion (valid for Matlab 7.5):

If you want to inspect the Editor-container, you will need to change lines 175-176 from

origContainer = container;
contentSize = [container.getWidth, container.getHeight];


origContainer = container;
if strcmp(container.getName,'Editor');
contentSize = [container.getWidth, container.getHeight];


Sebastian Hölz

Info for MATLAB 7.5.
An inconsistency in uitreenode.m (%MATLAB%\toolbox\matlab\uitools\uitreenode.m) prevents "findjobj" to work properly. You have to change the first line in "uitreenode.m" from ...

function node = uitreenode(value, string, icon, isLeaf)

... to ...
function node = uitreenode(dummy,value, string, icon, isLeaf)

... , then everything initializes just fine.

After fixing that, it's SWEET! I've just spend hours and hours writing down the hirarchy of objects and was just starting to think, how nice it would be to have everything at hand in "file"-browser ... well, you know it: it's all on the FEX, ... somewhere ...



ucd puri


Yair Altman

ucd puri - jControl and uiComponent are simply Matlab functions that enable easy access and usage of Java controls, which in general are more powerful than the basic Matlab controls. The FindJObj function is useful for finding the handle of a Java control within a Matlab figure, similarly to Matlab's basic findobj function.

Java control functionality can be googled (e.g., "java jslider") , or you can read any good book or online tutorial about Java Swing (e.g., Alternately, you can use my uiInspect submission on the Matlab File Exchange to see exactly which properties/methods/callbacks are available for any component (Java, Matlab or COM) -

Yair Altman

ucd puri

I implemented this function Dennis's way. it works perfect. Thanl all. but i did not understand how did you figured out AdjustmentValueChangedCallback attribute in line below

jSlider.AdjustmentValueChangedCallback = {@FollowSliceSliderCallback,guidata(gcbo)};

Which all other attributes i can use with jSlider.(.....)
and how to find ot about them.
Regards n Thanks for tips

ucd puri

HI All, One more stupid question if you dnt mind. I am an intermidiate user of matlab, and learning more. I did not exactly understood the difference between
1) jControl function
2) findjObj function, and
3) uiComponent function.
Regards n Thanks for help. Tanuj

Yair Altman

The R2008 warnings can be eliminated by typing:


I'll add it to a new version soon, but you can simply use this in your startup file or your Matlab Command Window.

Jesse Hopkins

Running this in R2008a brings up the warning:
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on
the MathWorks Web site.
> In findjobj>getRootPanel at 266
In findjobj at 164

Johnny Smith

I guess, ln 257 should be


instead of



Jack Zheng

a great piece of work! thanks!

Yair, is that possible for you to make it compatible with 08a? it causes a bunch of thread error/warning in 08a.

thank you!

Yair Altman

Peter - all you need to do to prevent scanning the menu-bar is to add the '-nomenu' option. For example: jObj=findjobj(hObj,'-nomenu'); Unfortunately, I could not find a way to scan the menu-bar without actually activating all menu options.

Peter Li

Is it just me or does everyone who uses this script have problem on initialization.

Whenever start my own script which uses findjobj, "it" scrolls through the top menu ('file', 'edit','view','insert',...'help'). This is a little annoying

Dennis Olly

Thanks for the reply, Yair!

I am using: % $Revision: 1.9 $ $Date: 2007/08/14 23:03:04 $ which is the version I get when clicking the .m button on Mathworks (this page). Is there indeed I later version?

Nevertheless, you provided the solution saying the control has to be rendered. I created both the uicontrol AND the javacallback in the OpeningFcn.
I left the creation of the uicontrol in place but now I moved the below lines of code to the OutputFcn (not sure if that's a proper place for such purposes though):

jSlider = findjobj( handles.sliceSlider );
jSlider.AdjustmentValueChangedCallback = {@FollowSliceSliderCallback,guidata(gcbo)};

Now it works perfectly. Thanks again!

Yair Altman

Thanks for your feedback Dennis.

Please ensure you're using the latest version of FindJObj (currently dating 2007-11-13). Also, when calling findjobj immediately after creating a UI control, you must let the Matlab/Java engine time to fully render the control. This can be done with a simple drawnow command, possibly followed by a small pause(0.01).


Dennis Olly

I found out that

jSlider = findjobj(hSlider)
ans = <1x0>

eventhough just doing


lists all java-objects including the slider.
Also, when just using the Command Window, it works find: I can create figure with a slider with a callback that continuously calls an .m file.


Dennis Olly

Using Matlab 7.5 (R2007b) and doing

1 hSlider = uicontrol('style','slider' );
2 jSlider = findjobj(hSlider);
3 jSlider.AdjustmentValueChangedCallback = @FollowSliceSlider_Callback;

I get:
No public field AdjustmentValueChangedCallback exists for class handle


'AdjustmentValueChangedCallback', @FollowSliceSlider_Callback );

I get no error, but the callback function is never reached.

Am I missing something here?
Thanks for any help

Yair Altman

Bob - the bottom tree branch that FindJObj displays is the Handle Graphics hierarchy - only the top branch is the Java hierarchy. If you don't see it, perhaps you're not using the latest version of FindJObj.

Bob W

This is interesting, would it be easy to organize the objects the way as they are thought of in the Child/Parent as the handle graphics user would see them?

Yair Altman

the cellfun behavior has changed in Matlab 7.1 - unfortunately FINDJOBJ relies on the new behavior, so you must have version 7.1+ to run. Sorry about the confusion...


Hello Yair!
Sorry for typing mistake in the post. The matlab command issued is "findjobj" and not "finjobj". I have not renamed the file. The file name is kept "findjobj.m" only. I ensure that script is run by setting breakpoints in the m-file.
So here I restate the problem.
If I issue the command, the figure window is created and I get following error message

>> findjobj
??? findjobj: Function name must be a string.

If I set breakpoint for error,the error is reported at line 234 of the code. The value of error variable is

K>> err

err =

message: 'findjobj: Function name must be a string.'

The Java version is

Java 1.5.0 with Sun Microsystems Inc. Java HotSpot(TM) Client VM (mixed mode)

with regards,


On MATLAB Version (R14) Service Pack 2 I get following error when findjobj is run (with and without arguments)

??? findjobj: Function name must be a string.

Mikhail Poda Razumtsev

It is the best piece of code on Matlab/Java I have ever seen in Matlab Central. I am very grateful to the author for sharing his knowledge.

MATLAB Release Compatibility
Created with R14SP3
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: UIINSPECT - display methods, properties & callbacks of an object

Inspired: inspect time series events, BacStalk, BiofilmQ, tweak, kristinbranson/JAABA, MATLAB Snippets, Stock Trader Journal, directorscut82/matbuttons, Microscopy Image Browser (MIB), attachScrollPanelTo - add scroll-panel to a uipanel or axes, Microscopy Image Browser 2 (MIB2), statusbar, getjframe - Retrieves a figure's underlying Java frame, enable/disable entire figure window, setDesktopVisibility, UIINSPECT - display methods, properties & callbacks of an object, Manage and Dock Figures into Group, Virtual Tackball, maximize, uhelp, Command window text, Graphical Wrappers, Reorderable Listbox, Colorize Document Bar, tortoise svn toolbar integration,, Realtime trading with Matlab and IB presentation files, fixuilabels, Programmatically scroll Variables Editor, embeddedmethodsviewer - show functions and methods within matlab editor, Figure from text file (supports HTML tags), Panic Simulator, tprintf -- Print to Second Terminal Window, GavriYashar/Matlab-Editor-Plugin, Copy Paste, Probability Distribution Plotter, Dynamic Search Box, checkVersion - Check for a newer file version on the File Exchange, figs2tabs - move figures into a single tabbed gui, Dicom Operator - EsmeProcess, Chess Master, smart_scrollbars fixes Matlab's listbox/editbox scrollbars to only show as needed, Message Logger, scatool, SessionManager, kview - Interface for signal/data easy visualization and processing

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!