Last week, I described the built-in PopupPanel object, and showed how it can be used to present popup messages with HTML content and even entire webpages. I explained that PopupPanel uses an internal browser object to achieve this. In fact, Matlab’s browser object predates PopupPanel by many years and quite a few releases. This browser object can be used as a stand-alone component that we can easily embed in our Matlab GUI applications.
Here is a simple example in which a Matlab Listbox uicontrol is used to select the contents of an adjacent browser component:
% Create a blank figure window f=figure('Name','Browser GUI demo','Num','off','Units','norm'); % Add the browser object on the right jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel; [browser,container] = javacomponent(jObject, [], f); set(container, 'Units','norm', 'Pos',[0.3,0.05,0.65,0.9]); % Add the URLs listbox on the left urls = {'www.cnn.com','www.bbc.co.uk','myLocalwebpage.html',... 'www.Mathworks.com', 'UndocumentedMatlab.com'}; hListbox = uicontrol('style','listbox', 'string',urls, ... 'units','norm', 'pos',[0.05,0.05,0.2,0.9], ... 'userdata',browser); % Set the listbox's callback to update the browser contents cbStr=['strs = get(gcbo,''string''); ' ... 'url = strs{get(gcbo,''value'')};' ... 'browser = get(gcbo,''userdata''); ' ... 'msg=[''<html><h2>Loading '' url '' - please wait''];'... 'browser.setHtmlText(msg); pause(0.1); drawnow;'... 'browser.setCurrentLocation(url);']; set(hListbox,'Callback',cbStr);
In this simple example, we can see how the Java browser object can easily be controlled by Matlab. Specifically, we use two modes of the browser: first we present an HTML message (‘Loading www.cnn.com – please wait‘) and then replacing this content with the actual webpage, if accessible. If the webpage is not accessible, an error message is displayed:
We can easily expand this simple example to display any HTML message or webpage, in a seamless integration within our GUI.
Now, who ever said that Matlab GUI looks static or boring???
In an unrelated note, I would like to extend good wishes to Ken Orr, who has left the Mathworks Desktop development team to join Apple a few days ago. You probably know Ken from his good work on the Desktop and the official Matlab Desktop blog. Hopefully, in his new position Ken will be able to influence Mac Java in a way that will reduce the numerous recurring issues that afflict Matlab Mac releases.
Related posts:
- GUI integrated HTML panel Simple HTML can be presented in a Java component integrated in Matlab GUI, without requiring the heavy browser control....
- The javacomponent function Matlab's built-in javacomponent function can be used to display Java components in Matlab application - this article details its usages and limitations...
- Customizing listbox & editbox scrollbars Matlab listbox and multi-line editbox uicontrols have pre-configured scrollbars. This article shows how they can be customized....
- Customizing Matlab labels Matlab's text uicontrol is not very customizable, and does not support HTML or Tex formatting. This article shows how to display HTML labels in Matlab and some undocumented customizations...
- FindJObj GUI – display container hierarchy The FindJObj utility can be used to present a GUI that displays a Matlab container's internal Java components, properties and callbacks....
- Inactive Control Tooltips & Event Chaining Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....
Tags: GUI, Handle graphics, HTML, Java, pure Matlab, uicontrol
Categories: Figure window, GUI, Handle graphics, Java, Medium risk of breaking in future versions, UI controls
This entry was posted
on Wednesday, December 9th, 2009 at 8:35 am PST
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.



Thanks Yair! I’ll do what I can to help influence Java on the Mac.
Thanks for a great tip! I have been struggling with the limited HTML capabilities of the JEditorPane but now you gave me a solution that really works out of the box.
Hi Yair,
Is it possible to view non-html links, say, a pdf file from within the matlab web browser? That should be without opening a new acrobat reader window.
Thanks
Sid
@Sid – I don’t think so. Even regular browsers need to use Acrobat (or another PDF reader like Foxit) to display PDF.
Hi Yair,
I’m designing a dialog similar to a throbber, indicating that some computation is running, but autonomous, contrary to matlab’s native waitbar. In order to save CPU ressources, i try to take advantages of animated GIF. After having considered timer functions for refreshing an axes, i finaly came out to use an HTML browser that can render basic animated GIFs. Your tip provides me a great solution, however, i’m wondering how i can remove the scrollbars that appear when i set the url to any image file :
I can’t see any method dealing with scrolling by typing :
I will try to work on browser size, but i appreciate if you can provide some hints.
Thanks.
Arnaud
@Arnaud – here’s a much lighter-weight alternative: