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

GUI integrated browser control

Posted By Yair Altman On December 9, 2009 | 44 Comments

Last week, I described the built-in PopupPanel object [1], 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''); ' ...

Loading '' url '' - please wait''];'... % no need for

'browser.setHtmlText(msg); pause(0.1); drawnow;'... 'browser.setCurrentLocation(url);']; set(hListbox,'Callback',cbStr);

Browser object integrated in Matlab GUI (click for large image) [2]
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) [3]
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 [4]. You probably know Ken from his good work on the Desktop and the official Matlab Desktop blog [5]. 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 [6].

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

44 Comments (Open | Close)

44 Comments To "GUI integrated browser control"

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

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

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 @ 20:44

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 @ 02:41

@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 @ 04:58

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 @ 09:34

@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 @ 07:39

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

Followup article: [13]

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

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:
[14] (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

[…] 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 @ 04:53

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 @ 15:56

@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 [15].

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

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 ( [17]) 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 @ 17:02

@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 @ 04:32


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 @ 17:39

@Kobbi – try to [18] your HTML

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

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 @ 23:52

@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

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 @ 13:16

@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 @ 05:18

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 @ 05:58

@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 @ 19:09

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

@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 @ 14:51

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 @ 15:03

@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 Reza On April 11, 2019 @ 10:32

I have the same problem. this Java widget got error in compiling via Matlab 2018!
Could you please show me how to solve this?

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

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

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

@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.

#30 Comment By Ragni On February 23, 2015 @ 21:06

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”.

#31 Comment By Leinylson On April 1, 2015 @ 20:57


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.

#32 Comment By Leinylson On April 1, 2015 @ 21:14

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

#33 Comment By Yair Altman On April 2, 2015 @ 02:03

I think the error message is pretty much self explanatory…

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

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?

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

@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

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

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!

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

@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!

#38 Comment By Nurdan On April 18, 2017 @ 15:27

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!

#39 Comment By Yair Altman On April 18, 2017 @ 22:39

search this website for “tree”

#40 Comment By Nurdan On April 27, 2017 @ 15:37

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!

#41 Comment By Yair Altman On December 3, 2017 @ 14:11

@Nurdan –


#42 Comment By Diego Shalom On June 29, 2017 @ 22:50

Hi Yair,
It works great after creating the figure using:

f=figure('Name','Browser GUI demo','Units','norm');

in Matlab 2015a. Several times I found useful codelets in this page, thanks!

I have a question. If the page is longer than the container, I need to scroll through. Can I track this scroll position in the webpage? Is this information available in any variable while scrolling?
Thanks you very much!

#43 Comment By H.A. Camp On August 23, 2017 @ 23:30

It’s not clear to me how to interact with HTML components from the resulting browser object. For example, if my HTML contains a simple form input box, how do I return the current string from the box? I imagine the procedure would be the same for a drop-down menu, or any other form component.

Is there a way to get/set HTML form component properties?

#44 Comment By H.A. Camp On September 22, 2017 @ 16:28

Looks like one solution to accessing HTML components can be seen here:


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

URL to article: https://undocumentedmatlab.com/articles/gui-integrated-browser-control

URLs in this post:

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

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

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

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

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

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

[7] GUI integrated HTML panel : https://undocumentedmatlab.com/articles/gui-integrated-html-panel

[8] Panel-level uicontrols : https://undocumentedmatlab.com/articles/panel-level-uicontrols

[9] Customizing listbox & editbox scrollbars : https://undocumentedmatlab.com/articles/customizing-listbox-editbox-scrollbars

[10] Icon images & text in Matlab uicontrols : https://undocumentedmatlab.com/articles/icon-images-in-matlab-uicontrols

[11] Transparent uipanels : https://undocumentedmatlab.com/articles/transparent-uipanels

[12] Customizing Matlab labels : https://undocumentedmatlab.com/articles/customizing-matlab-labels

[13] : https://undocumentedmatlab.com/blog/animated-busy-spinning-icon

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

[15] : https://undocumentedmatlab.com/blog/continuous-slider-callback/

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

[17] : https://undocumentedmatlab.com/blog/uiinspect/

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

[19] : https://www.mathworks.com/matlabcentral/answers/355723-tab-key-disabled-in-embedded-browser

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