- Undocumented Matlab - http://undocumentedmatlab.com -

GUI integrated browser control

Posted By Yair Altman On December 9, 2009 @ 8:35 am In Figure window,GUI,Handle graphics,Java,Medium risk of breaking in future versions,UI controls | 39 Comments

Last week, I described the built-in PopupPanel object [3], 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], ...
% 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''];'...  % no need for </h2></html>
      'browser.setHtmlText(msg); pause(0.1); drawnow;'...

Browser object integrated in Matlab GUI (click for large image) [4]

Browser object integrated in Matlab GUI

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:

Browser message when webpage is missing (click for large image) [5]

Browser message when webpage is missing

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 [6]. You probably know Ken from his good work on the Desktop and the official Matlab Desktop blog [7]. 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 [8].

39 Comments (Open | Close)

39 Comments To "GUI integrated browser control"

#1 Comment By Ken Orr On December 15, 2009 @ 3:53 am

Thanks Yair! I’ll do what I can to help influence Java on the Mac.

#2 Comment By Gunnar Ingestrom On January 22, 2010 @ 10:04 am

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.

#3 Comment By Sid On February 8, 2010 @ 8:44 pm

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.

#4 Comment By Yair Altman On February 9, 2010 @ 2:41 am

@Sid – I don’t think so. Even regular browsers need to use Acrobat (or another PDF reader like Foxit) to display PDF.

#5 Comment By Arnaud On August 18, 2010 @ 4:58 am

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.

#6 Comment By Yair Altman On August 18, 2010 @ 9:34 am

@Arnaud – here’s a much lighter-weight alternative:

iconsClassName = 'com.mathworks.widgets.BusyAffordance$AffordanceSize';
iconsSizeEnums = javaMethod('values',iconsClassName);
SIZE_32x32 = iconsSizeEnums(2);  % (1) = 16x16
jObj = com.mathworks.widgets.BusyAffordance(SIZE_32x32,'testing...');
    % do some long operation...

#7 Comment By Arnaud On January 24, 2013 @ 7:39 am

Hi Yair,

I’m just reading your response to my post I wrote… 2 years ago.
The need for a throbber was off the radar during this time, but finaly rises again, and your piece of code is actualy exactly what I was looking for.
Thank you for your help, and continue to keep this extremly usefull website alive.


#8 Comment By Yair Altman On April 16, 2014 @ 11:06 am

Followup article: [15]

#9 Comment By Yonatan On October 6, 2010 @ 9:29 pm

This works great.
I do have a slight problem – if the page I’m viewing has some dhtml pop up window, it shows like an error message and there’s nothing I can do – the whole program is stuck until I turn it off (click ok or something).
Here’s an example of such a web page:
[16] (simply let the page load, and then refresh the screen to see the popup).
Is there a way to monitor such messages and handle them via the code? Or maybe disable them?
Thanks :)

#10 Pingback By Customizing menu items part 3 | Undocumented Matlab On May 9, 2012 @ 11:01 am

[…] Mike has been with MathWorks since 2005 and has been responsible for maintaining the official MATLAB Desktop blog, together with Ken Orr. I’m not sure yet which direction the Desktop blog will take, and by whom, but in any case it won’t be the same. […]

#11 Comment By Ivan On December 25, 2012 @ 4:53 am

Hi, Yair!
Is it possible to track changes in browser object? For example, change listbox when we follow a link to another site.

#12 Comment By Yair Altman On December 27, 2012 @ 3:56 pm

@Ivan – the easiest way would be to check whether the browser object (or one of its sub-components) has a built-in event (Matlab callback) that you can use. Alternatively, you could try using a property-change listener as explained [17].

#13 Comment By thnxtay On May 2, 2013 @ 12:33 pm

I am having an issue with grabbing the HTML text from a particular website using the embedded browser. I took your code and dropped in the following URL:


In the “Database” drop down under the “Input” cell, select any one of the databases. It will load the data for that particular study.

OBJECTIVE: Capture the text on the page for the time section of the study being viewed; the text in the blue bar just above the graphs (“Selected Input:”).

PROBLEM: HTML text field in browser object is not updated after navigating away from welcome page. Need to find a way to get the HTML code that is specific to the study data that is being displayed.

1) Used uiinspect.m ( [19]) to find the displayed HTML for the data page of the study. Can’t find any field containing the new info.
2) Right clicked on the page and used the “Page Source” option. It shows the original welcome screen html
3) Right clicked on the page and used the “Refresh” option. This did not update the HTML text field of the browser object. It did keep you on the study page, and did not refresh to the welcome page, even though it had to resend the POSTDATA query.
4) Viewed the same page in Firefox and inspected the page source code. This gave me what I want; HTML code specific to the study.

Any help would be greatly appreciated. Thank you.

Here is the modified m-code from this post that has a link to the page that I am working with:

% 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 = {'http://www.physionet.org/cgi-bin/atm/ATM','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], ...
% 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=[''Loading '' url '' - please wait''];'...
      'browser.setHtmlText(msg); pause(0.1); drawnow;'...
% context menu
cmenu = uicontextmenu;
hcb1 = ['set(f, ''Color'', [0.9 0.6 0.5])'];
item1 = uimenu(cmenu, 'Label', 'change color', 'Callback', hcb1);

#14 Comment By Yair Altman On May 28, 2013 @ 5:02 pm

@thnxtay – I suggest that you load your webpage in some external browser that has more abilities to display the inner HTML code (e.g., Firebug on FireFox). Then you’d be able to see what goes on behind the scenes and try to use this info in the more-limited Matlab browser. If you would like further assistance on a consulting basis, please contact me via email.

#15 Comment By kobbi On May 21, 2013 @ 4:32 am


I tried to use the code example above, to load an html file that I have created into the GUI, but I got the following message (inside the UI browser):

“This file exceeds the maximum size for the MATLAB Web Browser. It will open in your system browser.”

and indeed the html was opened with in internet explorer.

Any idea how to solve this problem?


#16 Comment By Yair Altman On May 28, 2013 @ 5:39 pm

@Kobbi – try to [20] your HTML

#17 Comment By Brian On June 24, 2013 @ 3:03 am

This works great, thanks! Is there any way to add the browser menu bar to this panel (i.e. forward/back buttons?)

#18 Comment By Yair Altman On June 24, 2013 @ 11:52 pm

@Brian –

jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel;
jObject.addAddressBox(false);  % false=in toolbar row; true=in separate row
[browser,container] = javacomponent(jObject, [], gcf);
set(container, 'Units','norm', 'Pos',[0.3,0.05,0.65,0.9]);

#19 Comment By Mike On July 15, 2013 @ 12:53 pm

Do you know how to disable or modify the popup context menu that I get when using com.mathworks.mlwidgets.html.HTMLBrowserPanel ? I’m deploying a compiled app with an HTML viewer component, and I don’t want the users to be able to click “Evaluate selection” on selected text.

#20 Comment By Yair Altman On July 15, 2013 @ 1:16 pm

@Mike – this will require investigation. If you would like me to investigate this for you (for a consulting fee), send me an email.

#21 Comment By lichen On October 18, 2013 @ 5:18 am

As writen above, we can browse web page in the matlab GUI. Now there is a video frequency embed in the web page which is realized by applet(java), how can i process every frame image such as adding a moving mechanical arm to realize fusion

#22 Comment By Yair Altman On October 18, 2013 @ 5:58 am

@Lichen – you need to download the relevant video into Matlab and process it in Matlab. You cannot directly interact with it on the webpage.

#23 Comment By clara sergian On November 12, 2013 @ 7:09 pm

hi yair.

is it possible to integrate GUI on a web browser?? could you please show me how to solve this?

#24 Comment By Yair Altman On November 13, 2013 @ 10:14 am

@Clara – There is no simple answer. You can have your webserver call Matlab (on the server-side) to generate HTML/images. If you need interactivity then consider getting the Matlab Production Server ($$$).

#25 Comment By Bryant On October 6, 2014 @ 2:51 pm

Can this widget be used in a deployed application via MATLAB Compiler? I tried compiling your sample code in MATLAB R2013b and got the following error:

Error using playground (line 10)
Java exception occurred: 
java.lang.NoClassDefFoundError: com/teamdev/jxbrowser/BrowserType
	at com.mathworks.html.jxbrowser.BrowserHolder$Type.(BrowserHolder.java:13)
	at com.mathworks.html.jxbrowser.JxBrowserSettings.getBrowserTypeValues(JxBrowserSettings.java:45)
	at com.mathworks.html.jxbrowser.JxBrowserSettings.buildSupportedProperties(JxBrowserSettings.java:33)
	at com.mathworks.html.jxbrowser.JxBrowserSettings.(JxBrowserSettings.java:23)
	at com.mathworks.html.BrowserSettings.getAllSettingsInstances(BrowserSettings.java:59)
	at com.mathworks.html.BrowserSettings.(BrowserSettings.java:22)
	at com.mathworks.mlwidgets.html.HtmlComponentFactory.(HtmlComponentFactory.java:54)
	at com.mathworks.mlwidgets.html.HTMLBrowserPanel.(HTMLBrowserPanel.java:75)
	at com.mathworks.mlwidgets.html.HTMLBrowserPanel.(HTMLBrowserPanel.java:65)
Caused by: java.lang.ClassNotFoundException: com.teamdev.jxbrowser.BrowserType
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
	... 9 more


#26 Comment By Yair Altman On October 6, 2014 @ 3:03 pm

@Bryant – this article is an oldie, written in 2009. Since then (I believe in R2012a) Matlab changed its internal browser to the new JXBrowser. This means that you will need to modify the above code. I did it some months ago and I remember that it wasn’t too hard, but I can’t remember at the moment exactly what I did and I do not have the code (it’s at a client). So either you try to modify the code like I did back then, or contact me by email for a short consultancy to recreate what I did.

#27 Comment By Ragni On February 23, 2015 @ 10:10 am

Could you tell how to download a video file to matlab from web browser?

#28 Comment By Yair Altman On February 23, 2015 @ 10:23 am

@Ragni – don’t do it directly in Matlab: download the video using external software, save it on your disk, and then load this file in Matlab.

#29 Comment By Ragni On February 23, 2015 @ 9:06 pm

Thanks for your answer.
I have one more doubt. I have live video streaming running in Google Chrome browser. How can i import/read this live streaming to MATLAB such that I can read it using matlab function “inputvideo”.

#30 Comment By Leinylson On April 1, 2015 @ 8:57 pm


I have this error:

This page does not display correctly in your version of the MATLAB Web Browser.
Please use the link below to open the page in your default system browser:

I’m using the 2013 version. thanks.

#31 Comment By Leinylson On April 1, 2015 @ 9:14 pm

more one thing, how to play a video with audio in a gui matlab?

#32 Comment By Yair Altman On April 2, 2015 @ 2:03 am

I think the error message is pretty much self explanatory…

#33 Comment By Clement Val On May 26, 2016 @ 12:49 pm

I have a little trouble using this component in a Matlab class UI I have developed: although I delete the java objects in my destructor, “jxBrowser Chromium Native Process” remain in memory, until I close Matlab. Any idea how I can properly cleanup that?

#34 Comment By Yair Altman On May 26, 2016 @ 12:55 pm

@Clement – apparently you can dispose the browser object using its dispose() method. You can simply call it when the window closes. For example:

set(f, 'CloseRequestFcn', @(h,e) dispose(jObject));  % f is the figure handle

#35 Comment By Nurdan On April 18, 2017 @ 11:11 am

Hi Yair,
Thanks very much I love your website, it is so helpful.
I have a question.When I tried to run the above code it gives an error of Undefined variable”com” or class ”com.matworks.mlwidget.html.HTMLBrowserPanel” ıf you help that would be great. Thanks!

#36 Comment By Yair Altman On April 18, 2017 @ 11:31 am

@Nurden – of course Matlab gives this error if you mistype the class name (com.mathworks.mlwidgets.html.HTMLBrowserPanel) !!!
Next time copy-paste from the blog, don’t try to memorize long class names!

#37 Comment By Nurdan On April 18, 2017 @ 3:27 pm

Hi Yair,
Sorry for taking your time, I found that mistake pretty shortly after I asked the question here. Now it works and I cant thank you enough.
One more question; instead of a listbox, I would like to put a tree on the left side inside a panel so whenever I click on an item in the tree it would take me to a specific url that belongs to that item that I picked. I can create a tree with the help of other sources on the internet, but how can I put that tree in a uipanel? Any help will be appreciated. Thanks again!

#38 Comment By Yair Altman On April 18, 2017 @ 10:39 pm

search this website for “tree”

#39 Comment By Nurdan On April 27, 2017 @ 3:37 pm

Hello Yair,
Lets assume there is a link to ‘www.cnn.com’ on the RIGHT side in the browser in above example(GUI integrated browser control) and when I click on it , it will start showing cnn website. How can I move the selection highlight (blue) on to ‘www.cnn.com’?
Thanks very much!

Article printed from Undocumented Matlab: http://undocumentedmatlab.com

URL to article: http://undocumentedmatlab.com/blog/gui-integrated-browser-control

URLs in this post:

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

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

[3] described the built-in PopupPanel object: http://undocumentedmatlab.com/blog/customizing-help-popup-contents/

[4] Image: http://images.undocumentedmatlab.com/Browser.png

[5] Image: http://images.undocumentedmatlab.com/Browser_404.png

[6] a few days ago: http://explodingpixels.wordpress.com/2009/12/04/heading-to-apple/

[7] Matlab Desktop blog: http://blogs.mathworks.com/desktop/

[8] numerous recurring issues that afflict Matlab Mac releases: http://blogs.mathworks.com/desktop/2009/08/31/pouncing-on-snow-leopard/

[9] Customizing Matlab labels : http://undocumentedmatlab.com/blog/customizing-matlab-labels

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

[11] Inactive Control Tooltips & Event Chaining : http://undocumentedmatlab.com/blog/inactive-control-tooltips-event-chaining

[12] The javacomponent function : http://undocumentedmatlab.com/blog/javacomponent

[13] Tab panels – uitab and relatives : http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives

[14] Editbox data input validation : http://undocumentedmatlab.com/blog/editbox-data-input-validation

[15] : http://undocumentedmatlab.com/blog/animated-busy-spinning-icon

[16] : http://www.domainscalping.com/

[17] : http://undocumentedmatlab.com/blog/continuous-slider-callback/

[18] : http://www.physionet.org/cgi-bin/atm/ATM

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

[20] : http://en.wikipedia.org/wiki/Minification_(programming)

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