Recommendations for MATLAB Apps Using Java and ActiveX

Previously, MATLAB included app-building capabilities that relied on third-party technologies (Java Swing and Microsoft COM), which have become legacy UI frameworks. These capabilities include the undocumented JavaFrame property, javacomponent function, and 'v0' option of the uitable and uitree functions, as well as the actxcontrol function. MathWorks has transitioned its app building infrastructure to web technologies in response to customer requests for new web-based sharing workflows (such as MATLAB Web AppsMATLAB Online, and opening apps in focused view using GitHub repositories). As of R2025a, apps relying on these legacy UI frameworks will need to be updated.

You can use documented MATLAB functions instead of the undocumented legacy features. The examples below show how you can update your code. If you want help with usage scenarios not shown here, contact MathWorks technical support using the Contact Support page.

Documented MATLAB Recommendations

Tables

Enable table sorting

Table ColumnSortable property (introduced in R2019b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
mtable = uitable(fig,'Data',magic(3),'ColumnName',{'A','B','C'});
jscrollpane = findjobj(mtable);
jtable = jscrollpane.getViewport.getView;
jtable.setSortable(true);

Recommended MATLAB Functionality

fig = uifigure;
t = uitable(fig,Data=magic(3),ColumnName={'A','B','C'},ColumnSortable=true);

Output


Add color to table contents

uistyle (introduced in R2019b)

Java or ActiveX Functionality (Not Supported)

d = {'Apples',52;'<html><body style="background-color:yellow;">Oranges</body></html>',40;'Pears',25};
fig = figure;
t = uitable(fig,'Data',d);

Recommended MATLAB Functionality

d = {'Apples',52;'Oranges',40;'Pears',25};
fig = uifigure;
t = uitable(fig,Data=d);
s = uistyle(BackgroundColor="yellow");
addStyle(t,s,"cell",[2 1])

Output


Add HTML markup in table contents

uistyle (introduced in R2022a)

Java or ActiveX Functionality (Not Supported)

d = {'Apples',52;'<html><body style="background-color:yellow;">Oranges</body></html>',40;'Pears',25};
fig = figure;
t = uitable(fig,'Data',d);

Recommended MATLAB Functionality

d = {'Apples',52;'Oranges',40;'Pears',25};
fig = uifigure;
t = uitable(fig,Data=d);
s = uistyle(BackgroundColor="yellow");
addStyle(t,s,"cell",[2 1])

Output


Control table selection

Table Selection and SelectionType properties (introduced in R2022a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
mtable = uitable(fig,'Data',magic(3));
jscrollpane = findjobj(mtable);
jtable = jscrollpane.getViewport.getView;
jtable.changeSelection(2,2,false,false);

Recommended MATLAB Functionality

fig = uifigure;
t = uitable(fig,Data=magic(3));
t.Selection = [3 3];

Output


Trees

Create a tree

uitree (introduced in R2017b)

Java or ActiveX Functionality (Not Supported)

import com.mathworks.mwswing.checkboxtree.*
jRoot = DefaultCheckBoxNode('Food');
jNode = DefaultCheckBoxNode('Veggies');
jRoot.add(jNode);
jTree = com.mathworks.mwswing.MJTree(jRoot);
[jComp,hc] = javacomponent(jTree,[10,10,120,110],gcf);

Recommended MATLAB Functionality

fig = uifigure;
t = uitree(fig);
n1 = uitreenode(t,Text="Food");
n2 = uitreenode(n1,Text="Veggies");
expand(t)

Output


Create a check box tree

uitree (introduced in R2021a)

Java or ActiveX Functionality (Not Supported)

import com.mathworks.mwswing.*
jRoot = checkboxtree.DefaultCheckBoxNode('Food');
jNode = checkboxtree.DefaultCheckBoxNode('Veggies');
jRoot.add(jNode);
jTree = MJTree(jRoot);
jCheckBoxTree = checkboxtree.CheckBoxTree(jTree.getModel);
[jComp,hc] = javacomponent(jCheckBoxTree,[10,100,120,180],gcf);

Recommended MATLAB Functionality

fig = uifigure;
t = uitree(fig,"checkbox");
n1 = uitreenode(t,Text="Food");
n2 = uitreenode(n1,Text="Veggies");
expand(t)

Output


Add an icon to a tree node

uistyle (introduced in R2022a)

Java or ActiveX Functionality (Not Supported)

food = uitreenode('v0','Food','Food',[],false);
iconPath = fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif');
veggies = uitreenode('v0','Veggies','Veggies',iconPath,true);
food.add(veggies)
mtree = uitree('v0','Root',food,'Position',[10 10 120 110]);

Recommended MATLAB Functionality

fig = uifigure;
t = uitree(fig);
n1 = uitreenode(t,Text="Food");
n2 = uitreenode(n1,Text="Veggies");
imgStyle = uistyle(Icon="peppers.png");
addStyle(t,imgStyle,"node",n2)
expand(t)

Output


Add color, font options, or markup to a tree node

uistyle (introduced in R2021b)

Java or ActiveX Functionality (Not Supported)

import com.mathworks.mwswing.checkboxtree.*
jRoot = DefaultCheckBoxNode('Letters');
l1a = DefaultCheckBoxNode('<html><b>A</b></html>');
jRoot.add(l1a);
l1b = DefaultCheckBoxNode('<html><i>B</i></html>');
jRoot.add(l1b);
jTree = com.mathworks.mwswing.MJTree(jRoot);
[jComp,hc] = javacomponent(jTree,[10,10,120,110],gcf);

Recommended MATLAB Functionality

fig = uifigure;
t = uitree(fig);
n1=uitreenode(t,Text="Letters");
n2=uitreenode(n1,Text="A");
n3=uitreenode(n1,Text="B");
boldStyle = uistyle(FontWeight="bold");
italicStyle = uistyle(FontAngle="italic");
addStyle(t,boldStyle,"node",n2)
addStyle(t,italicStyle,"node",[n2 n3])
expand(t)

Output


Additional UI components

Create a slider

uislider (introduced in R2016a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jSlider = javax.swing.JSlider;
javacomponent(jSlider,[10,70,200,45],fig);

Recommended MATLAB Functionality

fig = uifigure;
sld = uislider(fig);

Output


Create a range slider

uislider (introduced in R2023b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jRangeSlider = com.jidesoft.swing.RangeSlider(0,100,0,100);
jRangeSlider = javacomponent(jRangeSlider,[20,20,200,80],fig);

Recommended MATLAB Functionality

fig = uifigure;
sld = uislider(fig,"range");

Output


Create a spinner

uispinner (introduced in R2016a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jModel = javax.swing.SpinnerNumberModel(24,20,35,1);
jSpinner = javax.swing.JSpinner(jModel);
jhSpinner = javacomponent(jSpinner,[10,10,60,20],fig);

Recommended MATLAB Functionality

fig = uifigure;
s = uispinner(fig,Value=24);

Output


Create an editable combo box

uidropdown (introduced in R2016a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
items = {'a','b','c','d'};
jModel = javax.swing.DefaultComboBoxModel(items);
jCombo = javacomponent('javax.swing.JComboBox',[100 100 80 22],fig);
jCombo.setModel(jModel);
jCombo.setEditable(true);

Recommended MATLAB Functionality

fig = uifigure;
dd = uidropdown(fig,Items={'a','b','c','d'},Editable="on");
jCombo.setEditable(true);

Output


Create an image or icon

uiimage (introduced in R2019a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jIcon = javax.swing.JLabel('<html><img src="https://www.mathworks.com/help/matlab/import_export/peppers_thumb.png" 
height="100" width="100"/></html>');
javacomponent(jIcon,[50 50 100 100],fig);

Recommended MATLAB Functionality

fig = uifigure;
im = uiimage(fig,Position=[50 50 100 100],ImageSource="peppers.png");

Output


Create a date picker

uidatepicker (introduced in R2018a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jPanel = com.jidesoft.combobox.DateChooserPanel;
[hPanel,hContainer] = javacomponent(jPanel,[10,10,200,200],fig);

Recommended MATLAB Functionality

fig = uifigure;
d = uidatepicker(fig);

Output


Create a hyperlink

uihyperlink (introduced in R2021a)

Java or ActiveX Functionality (Not Supported)

url = 'https://www.mathworks.com';
labelStr = ['<html><a href="">MathWorks</a></html>'];
jLabel = javaObjectEDT('javax.swing.JLabel',labelStr);
[hjLabel,hContainer] = javacomponent(jLabel,[100,100,250,20],gcf);
hjLabel.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.HAND_CURSOR));
hjLabel.setToolTipText(url);
set(hjLabel,'MouseClickedCallback',@(h,e)web(url,'-browser'))

Recommended MATLAB Functionality

fig = uifigure;
hlink = uihyperlink(fig,URL="https://www.mathworks.com",Text="MathWorks");

Output


Format text using HTML or LaTeX

Label Interpreter property (introduced in R2021a)

Java or ActiveX Functionality (Not Supported)

labelStr = ['<html>Hello <b>World</b></html>'];
jLabel = javaObjectEDT('javax.swing.JLabel',labelStr);
[hjLabel,hContainer] = javacomponent(jLabel,[100,100,250,20],gcf);

Recommended MATLAB Functionality

fig = uifigure;
lbl = uilabel(fig,Text="<html>Hello <b>World</b></html>",Interpreter="html",Position=[100,100,250,20]);

Output


Display a locally hosted video

uihtml (introduced in R2019b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
actx = actxcontrol('WMPlayer.ocx.7',[10 10 320 240],fig);
actx.URL = 'xylophone.oga';

Recommended MATLAB Functionality

fig = uifigure;
h = uihtml(fig);
h.Position = [10 10 320 240];
h.HTMLSource = '<video width="320" height="240" controls><source src="./xylophone.oga"></video>';

Output


Containers

Create a tab group with tabs

uitabgroup (introduced in R2014b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
[jTabbedPane, hContainer] = javacomponent('javax.swing.JTabbedPane',[20,50,200,200],fig);
jTabbedPane.addTab('Tab 1',javax.swing.JPanel);
jTabbedPane.addTab('Tab 2',javax.swing.JPanel);

Recommended MATLAB Functionality

fig = uifigure;
tg = uitabgroup(fig);
t1 = uitab(tg,Title="Tab 1");
t2 = uitab(tg,Title="Tab 2");

Output


Create a scrollable container

uipanel (introduced in R2018b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
hPanel = uipanel(fig,'Units','pixels','Position',[10 10 100 100]);
drawnow
jPanel = hPanel.JavaFrame.getGUIDEView.getParent;
jScrollPanel = javaObjectEDT(javax.swing.JScrollPane(jPanel));
jScrollPanel.setBorder([]);
pixelpos = getpixelposition(hPanel);
hParent = hPanel.Parent;
[hjScrollPanel, hScrollPanel] = javacomponent(jScrollPanel, pixelpos, hParent);
hScrollPanel.Units = 'pixels';
btn = uicontrol(hPanel,'Position',[200 200 70 20]);

Recommended MATLAB Functionality

fig = uifigure;
p = uipanel(fig,Scrollable="on",Position=[10 10 100 100]);
b = uibutton(p,Position=[200 200 70 20]);

Output


Figure Window Customization

Customize figure icon

Figure Icon property (introduced in R2020b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jFrame = get(fig,'javaframe');
jicon = javax.swing.ImageIcon('peppers.png');
jFrame.setFigureIcon(jicon);

Recommended MATLAB Functionality

fig = uifigure(Icon="peppers.png");

Output


Create an always-on-top or modal figure

Figure WindowStyle property (introduced in R2021a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jFrame = get(fig,'JavaFrame');
jWindow = jFrame.getFigurePanelContainer.getTopLevelAncestor;
jWindow.setAlwaysOnTop(true);

Recommended MATLAB Functionality

fig = uifigure(WindowStyle="alwaysontop");
% or
fig = uifigure(WindowStyle="modal");

Output


Maximize or minimize window

Figure WindowStyle property (introduced in R2018a)

Java or ActiveX Functionality (Not Supported)

fig = figure;
jFrame = get(fig,'JavaFrame');
jFrame.setMaximized(true);

Recommended MATLAB Functionality

fig = uifigure(WindowState="maximized");
% or
fig = uifigure(WindowState="minimized");

Output


Callbacks

Program a response to a user typing in a text area

TextArea ValueChangingFcn callback property (introduced in R2021b)

Java or ActiveX Functionality (Not Supported)

fig = figure;
[jField,hField] = javacomponent('javax.swing.JTextArea',[100 100 200 100],fig);
set(jField,'KeyPressedCallback',@(src,event)disp(getText(src)));

Recommended MATLAB Functionality

fig = figure;
[jField,hField] = javacomponent('javax.swing.JTextArea',[100 100 200 100],fig);
set(jField,'KeyPressedCallback',@(src,event)disp(getText(src)));

Output


Additional Component Layouts and Extensibility

Lay out UI components in a grid

uigridlayout (introduced in R2018b)

Output


Embed HTML, JavaScript®, or CSS content into your app and interface with third-party libraries

uihtml (introduced in R2019b)

Output


Create a class implementation of a reusable custom UI component

ComponentContainer (introduced in R2020b)

Output