- Undocumented Matlab - https://undocumentedmatlab.com/blog -

FindJObj – find a Matlab component’s underlying Java object

Posted By Yair Altman On January 6, 2010 | 69 Comments

In a previous post, I explained that all Matlab GUI (except the axes plotting engine) is based on Java components, and showed how we can use this information to display HTML contents in Matlab uicontrols [3]. In other posts [4], I have shown how a utility called findjobj can be used to access the underlying Java components to enable customizations that are unavailable in standard Matlab: setting the line location in an edit-box [5], customizing button appearance [6], setting uicontrol callbacks [7], or setting list-box mouse actions [8]. I have also shown how findjobj can be used to display the component hierarchy of complex Matlab containers such as the figure window [9], GUIDE [10] or the Editor [11].

The time is therefore well overdue for a formal introduction of findjobj, explaining its uses and internal mechanism. Of course, readers are welcome to continue using findjobj as a black-box utility, but I think important insight can be gained from understanding its inner details. Findjobj‘s code is available for free download on the MathWorks File Exchange [12]. It is one of my favorite submissions and is apparently well-liked by users, being highly reviewed and highly downloaded.

Findjobj has two main purposes:

  1. Find the underlying Java object reference of a given Matlab handle – Historically this was the original purpose, hence the utility’s name. Findjobj was meant to extend Matlab’s standard findobj function, which does not expose Java components.
  2. Display a container’s internal components hierarchy in a graphical user interface, to facilitate visualization of complex containers. This was later extended to also display and allow modification of the sub-components’ properties and callbacks.

Today I will focus on the first (programmatic) aspect; next week I will describe the second (GUI) aspect.

Findjobj‘s heart is finding a control’s underlying Java handle. Unfortunately, this is not exposed by Matlab except in very rare cases. As hard as I tried, I could not find a way to directly access the underlying Java-peer handle. I therefore resorted to getting the control’s enclosing Java frame (window) reference, and then working down its sub-components hierarchy until finding the Java object(s) which satisfy the position and/or class criteria. To get the enclosing Java frame (aka TopLevelAncestor), I use the Matlab figure’s undocumented JavaFrame property. Using this property issues a standard warning (since Matlab release R2008a) of becoming obsolete in some future Matlab release. Since it worked so far, I have turned off this warning in findjobj‘s code, but note that this code may well fail in some future Matlab version. If and when JavaFrame does become obsolete, be sure to look in this blog for workarounds…

Traversing the frame’s hierarchy presents several challenges: Main-menu items are accessed using different functions than other Swing components or sub-containers, and are not automatically accessible until first displayed. I have overcome this latter challenge by simulating a menu-open action in case menus should be searched (this is off by default since it takes several seconds and also changes the GUI focus). For “regular” sub-containers, sometimes we need to loop over getComponent(…) and in some other cases over getChildAt(…).

Another challenge was presented by the fact that Java positions start at (0,0) in the top left corner increasing rightward and downward, rather than starting at (1,1) in the bottom left and increasing upward as in Matlab. Moreover, Java positions are always pixel-based and relative to their parent container, which is different from Matlab (if the Matlab units is ‘pixels’ then the value is absolute; if ‘normalized’ then it returns a non-pixel value). To further complicate matters, some Matlab controls have a different size than their Java counterparts: some controls have a 5-pixel margins while others not, some controls are shifted by a pixel or two from their container’s border (for a total offset of up to 7 pixels), while some controls (such as popup-menus) have an entirely different reported size. In theory, we could use the Matlab component’s undocumented PixelBounds property (much faster than getpixelposition), but unfortunately PixelBounds turns out to be unreliable and returns erroneous values in many cases. Finally, different Java containers/components have different ways of returning their position: for some it is a getLocation() method, for others it is getX()/getY() and for others it is the X and Y properties (that sometimes have no corresponding getX()/getY() accessor methods!).

Having finally overcome all these challenges (and quite a few smaller ones, documented within the source code), I have wrapped the algorithm in a function interface that tries to emulate findobj‘s. Using findjobj can now be as easy as:

% Modify the mouse cursor when over the button
hButton = uicontrol('string','click me!');
jButton = findjobj(hButton);

Modified uicontrol cursor - a Java property

Modified uicontrol cursor - a Java property

…or as complex as:

% Find all non-button controls with the specified label
jControls = findjobj('property',{'text','click me!'}, 'not','class','button');

Space here is limited and findjobj is over 2500 lines long, so I have obviously not covered everything. I encourage you to download the utility [12] and explore the code, and I gladly welcome your feedback.

Categories: Figure window, GUI, Handle graphics, High risk of breaking in future versions, Java, UI controls, Undocumented feature

69 Comments (Open | Close)

69 Comments To "FindJObj – find a Matlab component’s underlying Java object"

#1 Comment By Peter On January 7, 2010 @ 3:44 am

Dear Yair

Thank you very much for your great, great website. One really gets a feel for what is going on behind the scens in matlab.

I have a few question related to the findobj application:

You say that everything except the Java plotting engine is based on Java. I would like though to use the panelling from findobj in an application with for insatnce a matlab plot in one of the panels. Does your comment mean that I will be unsuccesful with that? If not, can you please give me a quick hint on how to get this?

Second, when you publish fíndobj in “High risk of breaking…” what is the risk then? Does it include the panels feature that I am after or do you rather think of the more programmatic part of it?

Thank you very much in advance!


#2 Comment By Yair Altman On January 7, 2010 @ 6:20 am

Thanks Peter.

Unfortunately, you cannot embed a Matlab plot axis in a Java container (only Java components in a Matlab container). However, to solve this problem I have created the [19] that behaves exactly like a Java JSplitPane, and enables interactively-resizable panels with Matlab plots:

Two levels of UISplitPane, with customized dividers

Two levels of UISplitPane, with customized dividers

As for your second question, I indicated “High risk of breaking in a future version” because FindJObj is highly dependent on internal Matlab implementation, which may break without warning between Matlab releases. For example, the very next release (R2010a) might remove the JavaFrame property, on which findjobj relies. Of course, since I maintain this utility I will try to bypass the problem and upload a new version (and findjobj has an automated mechanism to detect and suggest this new version), but I cannot promise anything concrete. Some other undocumented features I believe to be less prone to breaking in future releases, and so they get a less severe warning. Note that I base the severity on gut instinct and calculated guesses – I have no official access to Matlab’s development roadmap.

#3 Comment By Peter On January 11, 2010 @ 6:15 am

Thank you very much Yair

I will have a look at the UIsplitpane utility. It seems more appropiate for my use.

Thanks again. It is a real cool site you have!


#4 Comment By Daniel On January 13, 2010 @ 8:24 pm

Your program is great, but I found some trouble using it. It seems like it only works with controls created by code. I tried to find underlying java object for controls created with GUIDE, and findjobj always returned empty handles arrays. it’s that posible? is there another way to find a JTextbox behind a uicontrol created with GUIDE?


#5 Comment By Yair Altman On January 14, 2010 @ 10:23 am

@Daniel – It works for me…
Perhaps you’re calling findjobj in your _OpeningFcn() instead of in your _OutputFcn() or in callbacks? This would explain the problem, since the GUI has not yet rendered onscreen in _OpeningFcn() (the figure is still invisible), so findjobj cannot find the Java handle.

#6 Comment By Daniel On January 14, 2010 @ 2:28 pm

Yair, you’re right. I was calling it in my OpenFcn() method. My purpose was set a InputVerifier to an edit control. Is there another callback in wich i can do that?

Thank you very much!

#7 Comment By Yair Altman On January 15, 2010 @ 12:35 am

@Daniel – as I said, simply attach your InputVerifier in the _OutputFcn() instead of in the _OpeningFcn(). Both of these functions are automatically created by GUIDE: _OpeningFcn() is invoked before the figure is made visible and the Java peers are created; _OutputFcn() is invoked immediately after it’s made visible, when the peers are in place.

I would be happy if you added a comment with your InputVerifier code, for the benefit of other readers. If the code is long, email me (altmany at gmail) and I’ll add a separate post about it.

#8 Comment By Daniel On January 15, 2010 @ 4:55 pm

Yair, i moved my code to the _OutputFcn, but findjobj still returns empty arrays. I couldn’t find out what is my error.
i’ve written a simple code which replaces uicontrols with javax.swing.JTextFields:

function [ output_args ] = ReemplazarControles(hObject)
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
    children = get(hObject,'Children');
    nSize = size(children);
    for i=1:nSize
        hControl = children(i);
        if isa(handle(hControl),'uicontrol') 
            cStyle = get(hControl,'Style');
            if strcmp(cStyle,'edit')==1
                sPosition = get(hControl,'Position');
                sUnits = get(hControl,'Units');
                sParent = get(hControl,'Parent');
                [text textcontainer] = javacomponent('javax.swing.JTextField',[0 0 100 100], hObject);
        if isa(handle(hControl),'uipanel')

it works fine, but JTextFields not response Tab key strokes.
I could use both methods. I don’t know wich is better.
I deeply appreciate your help

#9 Comment By Peter On January 29, 2010 @ 3:17 am

Dear Yair

I am sorry for this kind of java newbie question, but I am back using the panes from the findobj. Now, instead of including a figure (as I asked about above) in one of the panes I would like to put a uitable or preferably your createtable from the FEX. I have tried many approaches, but none of them successful. I would be very happy if you have any directions on how to do it or have an example.

Thank you very much in advance!

Best regards, Peter

#10 Comment By Yair Altman On January 29, 2010 @ 4:00 am

@Peter – look at the way I added the callbacks-table in the [20] and [21] utilities. The source code is available on the File Exchange.


#11 Comment By Peter On January 29, 2010 @ 4:31 am

Thanks Yair! I will try to figure it out from there… As long as I know it should be possible, it puts a little more power behind the effort.


#12 Pingback By Continuous slider callback | Undocumented Matlab On February 8, 2010 @ 7:08 am

[…] AdjustmentValueChangedCallback property that is useful for our purposes and is accessible using the FindJObj utility. Simply download FindJObj from the File Exchange, and then: hSlider = […]

#13 Pingback By Tabbed panes – uitab and relatives | Undocumented Matlab On June 23, 2010 @ 11:47 am

[…] This object is not directly exposed by uitabgroup, but can be found using the FindJObj utility […]

#14 Pingback By GUI integrated HTML panel | Undocumented Matlab On June 30, 2010 @ 12:19 pm

[…] for undocumented features we need the editbox’s underlying JTextPane handle. This is done using the FindJObj utility […]

#15 Pingback By Customizing uicontrol border | Undocumented Matlab On October 31, 2010 @ 12:08 pm

[…] we first need to get the uicontrol’s underlying Java reference. This is done using my FindJObj utility. The next step is to get the Java object’s Border property […]

#16 Comment By Sherif Elnabarawy On December 29, 2010 @ 7:44 am

Dear Yair , i am using findjobj to get the java handle of uitable to apply some java methods on it , but unfortunately using findjobj makes the uitabs and uitabgroups stop responding ! i can’t understand what’s going on but i hope that i am missing something so that i can fix and continue using it .
this is code sample to show what i am talking about , try and feedback me .
thanks a lot.

uitab('v0', findobj('Tag','view_tabgroup'), 'title', 'System Data','Tag','system_tab');
uitab('v0',findobj('Tag','view_tabgroup'), 'title', 'Network','Tag','network_tab');

#17 Comment By Yair Altman On December 29, 2010 @ 11:24 am

@Sherif – it works ok for me on WinXP R2010b. Perhaps you forgot a call to drawnow before using findjobj, or perhaps you’re using an old version of findjobj.

#18 Comment By Sherif Elnabarawy On December 30, 2010 @ 3:05 am

i am using WinXP R2009a , tabs is working fine until i call findjobj :S , my findjobj version is updated , called drawnow before and after findjobj , but nothing changed .
i don’t know if the matlab version is the problem or there is something else .
i’ll try anyway .

#19 Pingback By Tri-state checkbox | Undocumented Matlab On October 19, 2011 @ 7:04 am

[…] uicontrol, we need to first get its underlying Java component reference. This is done using the findjobj utility. We then update its UI wrapper to be the same as the CheckBoxTree‘s checkbox […]

#20 Pingback By HG2 update | Undocumented Matlab On May 15, 2013 @ 6:04 pm

[…] HG2 compared to HG1. This has no visual importance except in very rare cases, but it does affect my findjobj utility, which relies on the component’s position to find its underlying Java object. […]

#21 Pingback By Variables Editor scrolling | Undocumented Matlab On September 11, 2013 @ 12:39 pm

[…] instance we can find the handle to the appropriate com.mathworks.mlwidgets.array.ArrayTable with findjobj (remember that there could be multiple ArrayTables, one for each inspected variable). Finally, we […]

#22 Pingback By Rich-contents log panel | Undocumented Matlab On September 18, 2013 @ 7:02 am

[…] work since the allocated line height remains unchanged. We can fix this by playing around with the underlying Java object‘s RowHeight property, but that again is rather […]

#23 Pingback By Editbox data input validation | Undocumented Matlab On October 2, 2013 @ 10:07 am

[…] we first need to get the Matlab control’s underlying Java control. This is done using the findjobj utility: % Prepare the log editbox hEditbox = uicontrol('Style','edit', 'String','Matlab', […]

#24 Pingback By Editable combo-box | Undocumented Matlab On October 9, 2013 @ 8:39 am

[…] feed for updates on Undocumented Matlab topics.In previous articles, I explained how we can use findjobj to customize a Matlab uicontrol’s underlying Java control, thereby improving its appearance […]

#25 Pingback By Using JIDE combo-boxes | Undocumented Matlab On October 16, 2013 @ 7:00 am

[…] the ability to easily set the MaximumRowCount property (default value =8). On the other hand, using findjobj we can do the same thing with Matlab’s […]

#26 Pingback By Listbox layout customization | Undocumented Matlab On November 13, 2013 @ 1:14 pm

[…] class that extends the standard JList. We can get this component’s reference using the findjobj utility:>> hListbox = uicontrol('Style','List', 'String',{'item #1','item #2'}); […]

#27 Comment By Ruthy On January 12, 2014 @ 2:00 am


The function doesn’t work for matlab release 2013b.
Do you know how it will be possible to adjust it to work in this release?


#28 Comment By Yair Altman On January 12, 2014 @ 1:35 pm

@Ruthy – The findjobj function works perfectly well on R2013b. It is your specific situation that perhaps doesn’t work, so I would suggest that you carefully check your code.

#29 Pingback By Button customization | Undocumented Matlab On January 14, 2014 @ 12:57 pm

[…] JList object. We do this by using my FindJObj submission on the File Exchange (which was explained here):>> jButton = java(findjobj(hButton)) jButton = […]

#30 Comment By Christy On March 17, 2014 @ 1:41 am

Hey Mr. Altman,
i have a question. I do create objects on the living program. That means for example i have uitabs and with every new uitab i add i add an editbox. Now on the first two editboxes i have “javahandle_withcallbacks.com.mathworks.hg.peer.utils.UIScrollPane” directly but on the third box i get a 1-by-4 handle. How can i ask which one is the one i need?

#31 Comment By Yair Altman On March 17, 2014 @ 6:01 am

@Christy – You can make them have distinct properties (Position, Text etc.) and then you could filter by that.

#32 Pingback By checkClass | Undocumented Matlab On June 11, 2014 @ 11:01 am

[…] I’ve already written here about the FindJObj utility, both as a means for uncovering the underlying Java reference of Matlab GUI controls, and as a means to visualize the GUI hierarchy of a specified window or container. […]

#33 Pingback By Matlab GUI: Numeric input for serious work | Notes On June 17, 2014 @ 2:34 am

[…] Instead, I use the handles of the underlying Java swing components. Yair Altman wrote an excellent FinJObj function for finding those […]

#34 Comment By Kathi On August 8, 2014 @ 12:53 am

Dear Yair,
I have a question concerning invisible figures. As you already explained (to Daniel, January 2010),
findjobj will not find any underlying jaya components while the figure is still invisible.

However, I have a GUIDE created GUI and I need to call it, telling him to stay invisible: MyGUI(‘Visible’,’off’)

Naturally, I get a warning:
Warning: No Java reference was found for the requested handle, because
the figure is still invisible in MyGUI_OutputFcn()

Is there a way to find the java while the figure is still invisible?
Moreover, the code is working: I got a sortable table with single row selection.

Thank you very much,
And thank you for your wonderful web site.

Best regards,

#35 Comment By Yair Altman On August 8, 2014 @ 1:30 am

@Kathi – instead of making the figure invisible, try to simply place it off-screen, for example in Position [-1000,-1000,100,100]

#36 Comment By Mohsen On August 21, 2014 @ 12:20 am

Hi Yair,

I’ve used findjobj to align the row headers in my uitable. The problem is when I try to change the dimension of my table it does not allow the new row names to be visible.
for example, if I want to increase the row numbers from 5 to 10, the last 5 rows do not get visible!


#37 Comment By Sergey Kucheryavskiy On September 18, 2014 @ 4:16 am

Dear Yair,

I am trying to get GUI layout toolbox ( [22]) working with the new HG2 system, which will be default from 2014b. The toolbox uses property “PixelBounds” as an indicator that size of container has been changed. And there is a trigger:

obj.Listeners{end+1,1} = handle.listener( containerObj, findprop( containerObj, 'PixelBounds' ), ...
    'PropertyPostSet', @obj.onResized );

I changed this to:

obj.Listeners{end+1,1} = addlistener( containerObj, findprop(containerObj, 'PixelBounds'), 'PostSet', @obj.onResized );

But then I realised that this property is not available in HG2. Can you please recommend a substitution for that? Thanks a lot in advance!

#38 Comment By Yair Altman On September 18, 2014 @ 4:50 am

@Sergey – the GUI layout toolbox is incompatible with HG2 in several places, not just the one that you found. MathWorks is aware of this and I expect that they will update the FEX utility when 14b is finally released.

Rather than using the GUI toolbox, you can use [23]. By specifying non-inf WidthLimits and/or HeightLimits property values, you can fix the size/position automatically without needing a custom resize callback function.

#39 Comment By Sergey Kucheryavskiy On September 18, 2014 @ 4:59 am

Yes, now I see it as well: — problems with Children in TabPanel and some others. Actually it was the TabPanel I decided to use the GUI layout, otherwise I feel quite comfortable with GridBagLayout you recommended in some go your post. Will find a workaround for now and wait for the fixes.


#40 Comment By Niko On October 29, 2014 @ 11:09 am

Hi Yair,

Thank you so much for this amazing code! It allowed me access so much more java-based functionality not available in matlab… One problem I’m seeing though, is that when I have multiple instances of the same figure window open, findjobj works for the first instance, but not the later opened ones. Am I not using the code correctly, or maybe there is a way to work around this?

In the openingfcn of my figure:


And only the edit box in the first instance becomes in-editable.

Thank you very much!



#41 Comment By Yair Altman On October 29, 2014 @ 11:34 am

@Niko – findjobj should be places in the outputfcn() as I’ve explained in numerous places – it needs the figure window to be visible in order to find the Java components.

#42 Comment By H.A. Camp On December 30, 2014 @ 8:25 am

Hi Yair,

First, thank you for your new book! Your last one has been invaluable to me, and I eagerly await the new arrival…

With release R2013b, I cannot seem to get this simple code (from your article above, as well as page 356 in your Undocumented Secrets book) to work:

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

No errors are generated, but the button component’s cursor does not change to the expected hand. I have verified that the code works as advertised using R2012b, but not R2013b… am I doing something wrong, or is this expected behavior in the later MATLAB releases? Is there a workaround for newer releases?

Many thanks for your efforts.

#43 Comment By Yair Altman On December 30, 2014 @ 8:58 am

It works ok for me, all the way up to R2015a…

Try to add drawnow; pause(0.01); and/or download the latest version of findjobj from the Matlab File Exchange.

#44 Comment By H.A. Camp On December 30, 2014 @ 9:49 am

I’ve verified that I’m using the latest version of findjobj, but I still get the same behavior with or without the drawnow/pause addition. Hmm, I’m not sure how to figure out what’s wrong… Any ideas?

#45 Comment By John On March 3, 2015 @ 9:26 am

A significant part of my work is developing MATLAB-based GUIs for engineering R&D applications; as such, I have referenced and used your information and the findjobj utility; they are very useful – thank you!

I’ve got a case where I’m using an “ActionPerformedCallback” for an edit control; in the callback I would like to get back the MATLAB edit control handle from the Java edit control peer (that is, the reverse of findjobj). Is this possible? I can always hunt down the MATLAB edit control by first getting the current figure and looking in that figure, but I wanted to see if there was an easy way to get back the MATLAB handle directly from the Java object.

Best regards,


#46 Comment By Yair Altman On March 3, 2015 @ 10:14 am

@John – there is no direct way to get the Matlab handle, but you can set it in your Java handle’s ApplicationData when you first find it using findjobj:

hEditbox = uicontrol('Style','edit', ...);
jEditbox = findjobj(hEditbox);
setappdata(jEditbox, 'MatlabHandle',hEditbox);

Then within your callback you could getappdata(jEditbox,'MatlabHandle') to get back the Matlab handle.

As an alternative, you could pass the Matlab handle as an extra (third) input argument to your editting callback function:

jEditbox.ActionPerformedCallback = {@myEditboxCallback, hEditbox};
function myEditboxCallback(jEditbox, eventData, hEditbox)

#47 Comment By John On March 3, 2015 @ 12:23 pm

Awesome – thank you, Yair!


#48 Comment By Adam On August 31, 2015 @ 5:44 am

These lines of code give me the following Java exception errors. Can you please help?

jEditbox = findjobj(editBoxHandle,'nomenu');
jEditbox.setText('some string');
Exception in thread “AWT-EventQueue-0″ java.lang.NullPointerException
at javax.swing.text.DefaultCaret.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paintSafely(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.paint(Unknown Source)
at javax.swing.plaf.basic.BasicTextUI.update(Unknown Source)
at javax.swing.JComponent.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

#49 Comment By Yair Altman On August 31, 2015 @ 11:34 am

@Adam – try to ensure that your editbox is fully visible onscreen when you issue the findjobj() function. Also, ensure that you are using the latest version of the findjobj() utility from the File Exchange. Also, try adding a short delay before running findjobj(), [24]. For example:

drawnow; pause(0.05);
jEditbox = findjobj(editBoxHandle);
jEditbox.setText('some string');

#50 Comment By Adam On August 31, 2015 @ 12:53 pm

Thank you for responding but none of these suggestions helped. Another user is suffering from the exact same problem. [25] Workaround he is suggestiong on this SO page works for me. No matter what I have tried (including but not limited to Null checks)

jEditbox.setText('some string');

is causing the Java exception errors. Running R2014a on a Windows machine.

#51 Comment By ML On September 2, 2015 @ 7:51 am

A guess, and only a guess, is that the UI is making a call that expects the caret to have been set when it has not been. A test would be to see if jEditbox.getCaret() called before setText(…) returns null.

#52 Comment By Ravi Goyal On October 26, 2015 @ 4:59 am

Dear Yair,

I am using findjobj in a GUI created for the Institute I work and it functions perfectly. In order to speed up the GUI I tweaked a bit around and we also just ordered your latest book (so far only used google snippets). Anyways, using the profiler the longest time I spend is using findjobj which I call regularly (I have a jtable included with cellcolorpicker ect…)

Calls with the longest time:

findjobj>traverseContainer and in there lines 507 and 580

Is there anyway to speed up this portion, or is it possible to save a javahandle into a matlab handle so I can just reuse it. All my functions where I use the findjobj function use

jscroll = functions.java_table.findjobj(handles.eis_data_table); 
jtable = jscroll.getViewport.getComponent(false);

Thanks and best regards

#53 Comment By Yair Altman On October 26, 2015 @ 5:08 am

@Ravi – You can store the Java handles in your Matlab code variables, for later reuse. You can also use findjobj with the ‘persist’ input to avoid the need to rescan the figure contents each time. This of course depends on that new components were not added since the last time that you ran the function.

#54 Comment By Ravi Goyal On October 26, 2015 @ 6:17 am

Thank You Yair,

Using persist and set/getappdata, makes the whole thing way more responsive : )

Perfect, thanks a lot.

#55 Comment By Travis On May 18, 2016 @ 7:18 pm


I am trying to set the position in a uitable, but I can’t for the life of me find how to change the ‘value’ field for the vertical scroll bar. Using your interface I can see where it is, but I am unsure how to navigate java and its components.

I have a variable with the uitable in question:

A = findjobj(TABLE1)

but that is as far as I have been able to get. Any suggestions would be very helpful.

Thank you.

#56 Comment By Payam Nia On May 26, 2016 @ 12:33 am

Dear Yair,
I have the same issue also.
I am trying to define the vertical scroll bar’s position.


#57 Comment By Yair Altman On May 26, 2016 @ 12:37 am

@Payam – see here: [26]. Once you get the scrollpane handles you can modify the relevant scrollbar properties, including their positions.

#58 Pingback By Listbox selection hacks | Undocumented Matlab On July 13, 2016 @ 6:36 pm

[…] We can solve both of these problems using the listbox’s underlying Java component, which we can retrieve using my findjobj utility: […]

#59 Comment By Akshay On November 18, 2016 @ 11:24 am

I need create a round pushbutton in matlab gui. As it is not directly available in matlab gui, I was thinking to take it using java and then use it in matlab.
I have some questions regarding this.
1) How to identify that java component(round pushbutton)?
2) will findjobj help me doing this?
3) Is there any other method? I dont want to wrap circular images on square pushbuttons.

#60 Comment By Yair Altman On November 18, 2016 @ 11:36 am

findjobj can be used to find the underlying Java control of an existing Matlab GUI control (e.g., pushbutton). You can then modify the control’s Border as explained here: [27]

#61 Comment By Akshay On November 18, 2016 @ 11:49 am


Ok. Can I customize default square pushbutton to have circular border?

#62 Comment By Yair Altman On November 18, 2016 @ 12:21 pm

@Ashkay – did you bother to read what I just sent you? You need to read the material and then search online to see how to create a rounded Java Border.

#63 Comment By Akshay On November 19, 2016 @ 1:09 pm


Hope you are doing fine. I have went through the document for customizing the border.
Let me rephrase again to have we both on the same page, I need your help in understanding how to override the default Push Button border properties in java and refer the same in Matlab (need to override the default border function).

I am quite new to MATLAB and don’t know how these two languages are exchanging their objects. I would really appreciate if you provide me the more details.

Thanks for your time and support as always! :-)

#64 Comment By Xiangrui Li On April 18, 2017 @ 4:34 pm

Hi Yair,
Just in case you don’t know, Matlab Central web update likely breaks pattern search in checkVersion(). I use the similar method to your code, and realized this problem.
My current solution is to search ‘user_version’, which seems reliable.

#65 Comment By Omar On March 19, 2018 @ 10:36 am

Hello Yair,

I am using MATLAB R2017a and I get an “Undefined function or variable ‘findjobj’.”-Error when using findjobj(text). findobj(text) works tho.
Is this no longer supported?

#66 Comment By Yair Altman On March 19, 2018 @ 10:39 am

Omar – findjobj is not a built-in Matlab function, it is a function that you need to download from the Matlab File Exchange, as the article clearly states (read it!)…

#67 Comment By Eddie On September 19, 2018 @ 6:06 pm

I just downloaded 2018b and findjobj does not work on uicontrol anymore :(

For example,

Returns an empty handle in 2018b, but in 2018a that is not a problem.

#68 Comment By Yair Altman On September 23, 2018 @ 1:30 pm

@Eddie – try to download the latest version of findjobj and then try again, it works well on all Matlab versions, including 18a and 18b.

#69 Comment By Nivetha On March 27, 2019 @ 12:46 pm

Hi Yair,

Sorting of numeric values in UITable is not working . Any workaround or fix?

Article printed from Undocumented Matlab: https://undocumentedmatlab.com/blog

URL to article: https://undocumentedmatlab.com/blog/findjobj-find-underlying-java-object

URLs in this post:

[1] Image: http://undocumentedmatlab.com/feed/

[2] email feed: http://undocumentedmatlab.com/subscribe_email.html

[3] display HTML contents in Matlab uicontrols: https://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/

[4] other posts: https://undocumentedmatlab.com/blog/tag/findjobj/

[5] setting the line location in an edit-box: https://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/

[6] customizing button appearance: https://undocumentedmatlab.com/blog/button-customization/

[7] setting uicontrol callbacks: https://undocumentedmatlab.com/blog/uicontrol-callbacks/

[8] setting list-box mouse actions: https://undocumentedmatlab.com/blog/setting-listbox-mouse-actions/

[9] figure window: https://undocumentedmatlab.com/blog/figure-toolbar-customizations/

[10] GUIDE: https://undocumentedmatlab.com/blog/guide-customization/

[11] Editor: https://undocumentedmatlab.com/blog/accessing-the-matlab-editor/

[12] MathWorks File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/14317

[13] FindJObj GUI – display container hierarchy : https://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy

[14] Faster findjobj : https://undocumentedmatlab.com/blog/faster-findjobj

[15] Matlab and the Event Dispatch Thread (EDT) : https://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt

[16] Frameless (undecorated) figure windows : https://undocumentedmatlab.com/blog/frameless-undecorated-figure-windows

[17] GUI integrated browser control : https://undocumentedmatlab.com/blog/gui-integrated-browser-control

[18] HG2 update : https://undocumentedmatlab.com/blog/hg2-update

[19] : http://undocumentedmatlab.com/blog/uisplitpane/

[20] : http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects

[21] : http://www.mathworks.com/matlabcentral/fileexchange/17935-uiinspect-display-methodspropertiescallbacks-of-an-object

[22] : http://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox

[23] : http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives

[24] : http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt

[25] : http://stackoverflow.com/questions/24021157/error-setting-text-property-of-a-matlab-uicontrol-using-its-java-handle

[26] : http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars

[27] : http://undocumentedmatlab.com/blog/customizing-uicontrol-border

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.