Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

FindJObj GUI – display container hierarchy

January 12, 2010 7 Comments

In my previous post, I explained how the findjobj utility can be used to access a Matlab component’s underlying Java component. Findjobj has another role: displaying the component hierarchy of complex Matlab containers such as the figure window, GUIDE or the Editor.
When findjobj is called with no output arguments, the function infers that the user requests to see the GUI version, rather than to get the control’s Java handle:

>> findjobj(gcf);  % or: findjobj(gcf)

>> findjobj(gcf); % or: findjobj(gcf)

FindJObj GUI (click to zoom)
FindJObj GUI (click to zoom)

There are several note-worthy aspects in this graphical hierarchy presentation:
The hierarchy tree itself is displayed using the internal com.mathworks.hg.peer.UITreePeer Java object. This is the object that underlies the semi-documented uitree function. The hierarchy sub-components are presented as tree nodes, each having a separate icon based on the component type. In some cases (toolbar buttons for example), the component’s icon image is used for its corresponding tree node. A javax.swing.JProgressBar is presented while the tree is being populated, an action that can take a few seconds depending on the target figure’s complexity. Some tree branches which are normally uninteresting are automatically collapsed: hidden containers (these are also grayed-out), menubars, toolbars and scrollbars. In parallel to the Java container hierarchy, a separate tree branch is presented with the corresponding Matlab (Handle-Graphics, or HG) hierarchy.
Another GUI example - note the hidden (gray) items, the HG tree branch and the auto-collapsed MJToolBar container
Another GUI example - note the hidden (gray) items, the HG tree branch and the auto-collapsed MJToolBar container

Each node item gets a unique tooltip (see top screenshot above). Similarly, a unique context-menu (right-click menu) is attached to each node item with actions that are relevant for that node:
Item-specific context-menu
Item-specific context-menu

Finally, a node-selection callback is attached to the tree, that will flash a red border around the GUI control when its corresponding Java node-item is clicked/selected:
FindJObj - flashing red border around a toolbar icon
FindJObj - flashing red border around a toolbar icon

Once the tree was done, I set out to display and enable modifications of component properties and callbacks in separate adjacent panels. I used the internal com.mathworks.mlwidgets.inspector.PropertyView component to display the properties (this is the JIDE component that underlies the built-in inspect function). To prevent a JIDE run-time alert, I called com.mathworks.mwswing.MJUtilities.initJIDE. A label is added to the table’s header, displaying the currently selected sub-component’s class (e.g., “javax.swing.JButton”), and a tooltip with a color-coded list of all the control’s properties.
The callbacks table was implemented using com.jidesoft.grid.TreeTable to enable easy column resizing, but this is otherwise used as a simple data table. A checkbox was added to filter out the 30-odd standard Swing callbacks, which are non-unique to the selected sub-component (tree node). All the panels – tree, properties and callbacks – are then placed in resizable javax.swing.JSplitPanes and presented to the user.
I have omitted mention of some other undocumented features in findjobj. After all, space here is limited and the function is over 2500 lines long. I encourage you to download the utility and explore the code, and I gladly welcome your feedback.

Related posts:

  1. FindJObj – find a Matlab component's underlying Java object – The FindJObj utility can be used to access and display the internal components of Matlab controls and containers. This article explains its uses and inner mechanism....
  2. Faster findjobj – the ubiquitous findjobj utility has been significantly improved for speed for the most common use case. ...
  3. cprintf – display formatted color text in the Command Window – cprintf is a utility that utilized undocumented Matlab desktop functionalities to display color and underline-styled formatted text in the Command Window...
  4. uitree – This article describes the undocumented Matlab uitree function, which displays data in a GUI tree component...
  5. uiinspect – uiinspect is a Matlab utility that displays detailed information about an object's methods, properties and callbacks in a single GUI window....
  6. IP address input control – A built-in JIDE control can be used in Matlab GUI for IP-address entry/display. ...
FindJObj GUI Handle graphics Java JIDE uicontrol Undocumented feature
Print Print
« Previous
Next »
7 Responses
  1. JIDE Property Grids | Undocumented Matlab April 21, 2010 at 22:55 Reply

    […] The Matlab inspector can be embedded, with not-too-much effort, within Matlab GUI applications. Examples of this can be found in the FindJObj and UIInspect utilities. […]

  2. Patrice Tscherrig September 13, 2010 at 23:37 Reply

    Hi

    I really love this tool. Perfect! One question – I really did not find it out myself. How do you manage the resize behavior of the tree pane? I.e. that you can move over the mouse on the tree pane and adjust it to make it less wide?

    Best Regards,
    Patrice

    • Yair Altman September 14, 2010 at 14:58 Reply

      @Patrice – findjobj uses JSplitPanes, which enable easy resizing of the left/right or top/bottom panes. I simply placed the tree in the top left pane and the JSplitPane control took care of the rest. Easy.

  3. Hannes September 24, 2014 at 05:38 Reply

    Hey,

    Is there no “easier” or quicker way to find the underlying java object/handle to my hg object then using findjobj?

    I mean, I gave it a try and took a look at the findjobj() function. It is indeed a mighty tool. But its also a blown up one. As far as I could find out, it tries to list all child components of my figure to find the requested handle. Ofcourse, this consumes time.

    In addition, it must make the figure visible to be able to find all children. This may be distracting for users. Lets say the figure is not visible during initilization. However, when my code hits the part where I am looking for my java object, the figure is made visible and invisible again by findjobj(). Yes, the figure is actually not visible because it gets positioned outside the screen, yet the icon for the figure in the windows taskbar briefly appears and then disappeares. You know what I mean? This can be in particular distracting when I must call findjobj() several times.

    Is there a workaround for this?

    Regards
    Hannes

    • Yair Altman September 24, 2014 at 05:46 Reply

      @Hannes – perhaps there is a simpler way but I am not aware of it. If you ever discover such a way, let me know and I’ll be happy to scrap findjobj. Until then, this is the only game in town. So you should direct your complaints to MathWorks for not exposing a simpler way, rather than to me…

      • Hannes September 24, 2014 at 06:39

        @Yair — That wasn’t a complain at all! Just wondering ;). Maybe sometimes the guys at MathWorks wonder, too. After all, its not that big of deal. Thank your for your quick reply :).

        Cheers
        Hannes

      • Hannes September 26, 2014 at 01:39

        @Yair — Sleep eluded me over the last 2 nights because of this problem. Hence, I used your findjobj() tool to work myself into the Java-UI-tree findjobj(gcf) provides. Maybe I found a plain way to get what I want: to have a function that returns the underlying Java UI component to a uicontrol (handle), without having to confront the problem I previously described.

        I know its neither a foolproof tool nor a very robust one. Still, it works for my problem very well.

        That’s my take on it.
        http://hpewd.dorado.uberspace.de/getUIcontrolJHandle.m

        Maybe you find some time to take a look on it :).

        Thank your for your advice and great tool findjobj().

        Best regards
        Hannes

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top