Clear Filters
Clear Filters

deprecated javacomponent and javaframe

77 views (last 30 days)
Bruno Luong
Bruno Luong on 12 Sep 2019
Commented: David Sampson on 14 Dec 2022
Starting from R2019b we are warned that javacomponent and javaframe property will be removed.
This is a bad news for me (and I guess also for Yair and his wonderful blog).
I would like to open this thread so tips and tricks for replacement during the transition.
For example I use javacomponent to drag the file/folder on windows explorer into a GUI, not sure how I can do that when it will be removed.
Xiangrui Li
Xiangrui Li on 27 Oct 2019
Edited: Xiangrui Li on 28 Oct 2019
I thought uihtml in R2019b may make the file drag-n-drop easier. There are many example of code, like this one, working for web page. But when I tried it on uifigure, it won't accept the drop at all. Anyone knows if there is a switch to turn the drop on somewhere?
Edit: Here is the minimum code I tested:
<div id="dropZone" style="width: 120px; height: 100px; border: 2px solid red">Drop a file here</div>
<div id="textZone" style="width: 360px; height: 40px"></div>
<script type="text/javascript">
var dropZone = document.getElementById('dropZone');
dropZone.addEventListener('dragover', function(e) {e.preventDefault();});
dropZone.addEventListener('drop', function(e) {
document.getElementById('textZone').innerHTML = e.dataTransfer.files[0].name;
Save the above as DnD_test.html into Matlab pwd. Open it in web browser, and drag and drop a file from OS file manager into the red box. The file name will show up, indicating DnD works.
In Matlab (R2019b+), load the html into a uifigure:
fig = uifigure('Position', [200 200 380 200]);
h = uihtml(fig, 'Position', [10 10 360 180]);
h.HTMLSource = './DnD_test.html';
When dragging a file into the box at uifigure, no-DnD symbol shows up.
Martin Lechner
Martin Lechner on 2 Nov 2019
Using "Using form input for selecting" from your mentioned HTML Rocks tutorial is working.
I'm no expert in HTML and JavaScript, but if I drop a file in your example somewhere in the browser window (out of your drop zone) the complete browser window is replaced by my content (only works in a browser, not in a Matlab figure). So I think this drag and drop support is disabled for this reason in Matlab UI figures.

Sign in to comment.

Answers (4)

Yair Altman
Yair Altman on 16 Sep 2019
I am very sorry to say that I am not aware of any easy way to make the transition from a Java-rich GUI to uifigures. All the main UI components are available (and then more), but many customizations of the components that are possible in Java are missing (for example, Border, Renderer, Editor etc.) not to mention the 30+ Swing callbacks for mouse/keyboard/action events that make Java GUIs "come to life".
In addition, there are simply too many fundamental differences that [IMHO] would foil any automated conversion attempt. For example, uifigure [still] do not have toolbars, toolstrips, customizable icon, or non-pixel units (esp. normalized).
Moreover, the fantastic GUILT (GUI Layout Toolbox), on which many existing GUIs depend, still does not have a uifigure variant (the new grid layout/container fills much of the need but a one-to-one variant of GUILT would remove a huge amout of necessary rework).
The new uihtml and uistyle functions look good at first glance, but in fact provide only a limited solution. We [still] have no documented way to customize existing uicomponents with our own CSS and JavaScript code, nor the ability to apply project/figure-wide CSS templates and JS functions. I can certainly understand MathWorks for not willing to commit its new UI framework to specific technologies such as CSS and JS, but the end result is that users are severly limited in their ability to customize their UIs.
The bottom line is that [at least at the current time] it looks like users need to manually redevelop their uifigure GUIs. Even with this manual redevelopment, we are severly limited in the new uifigure's customization compared to legacy Java-based UIs. Hopefully these limitations will be resolved over time, leaving us with just the benefits of uifigures over legacy figures (there are many of those as well, don't get me wrong).
Nobody should really be upset about this: we all knew that using undocumented Java in Matlab GUI carried a risk and would not last forever. It worked well for nearly 20 years (and possibly for several more years in the future). This is longer than the lifetime of most tecnologies - How long did DOS programs live before they had to be redeveloped for Windows, then again for the web, then again for mobile? In fact, Matlab's Java UI lifetime may turn out to be longer than the future lifetime of uifigures, before we will need to redevelop our GUIs yet again to fit some future new technology.
Speculating about the future, I hope that MathWorks will make a gradual transition i.e., first remove GUIDE but keep Java GUI running, then (in a subsequent release) make uifigure the default figure type but keep legacy figures running, then (in another subsequent release) remove the Java dependency in all of Matlab but still enable legacy Java-based GUIs to run using either the built-in JVM or (when they stop shipping Java) a user-installed JVM. Such gradual steps will make the transition from Java to web-based UIs much smoother over time and will allow users enough time to (re)develop the UIs without time pressure. The business benefit to MathWorks will be that users will keep upgrading their Matlab release, avoiding the debacle of R2014b in which many users stopped upgrading and stuck with 14a since the new HG2 broke (or froze) their programs. Having said that, MathWorks has many business and R&D considerations that I am not aware of, so they may decide not to follow my suggested gradual transition path: we might discover that R2020a brakes all legacy Java GUI - I hope not, but I really have no idea.
David Sampson
David Sampson on 14 Dec 2022
Simple GUI Layout Toolbox containers work from R2020b. Flex containers work from R2022a. We hope to fix all remaining issues in Q1 2023.

Sign in to comment.

Martin Lechner
Martin Lechner on 6 Nov 2019
Set the Icon of an uifigure
My colleague Andreas Justin had found a solution to get the webwindow of an uifigure (see the attached function). This solution don't throws the warning "Warning: The JavaFrame figure property will be removed in a future release." as the usage of mlapptools.getWebWindow(figWeb) does (see mlapptools).
This webwindows has the property Icon which can be changed by setting the path to a new icon (in Windows it must be an *.ico file).
% Web based Matlab figure (uifigure) -> webwindow is returned
figWeb = uifigure
ww = getWebWindowOfUiFigure(figWeb);
% set a new icon; on Windows systems it must be an .ico file
ww.Icon = fullfile(matlabroot, '\toolbox\matlab\toolstrip\web\image\uicontainer.ico')
Function to get the webwindow of an uifigure:
function webWindow = getWebWindowOfUiFigure(fig)
% returns the underlaying webwindow of the given figure handle in case of an uifigure, otherwise it returns an empty
% webwindow array
% standard Java based Matlab figure -> no webwindow is returned
fig = figure
ww = getWebWindowOfUiFigure(fig);
% Web based Matlab figure (uifigure) -> webwindow is returned
figWeb = uifigure
ww = getWebWindowOfUiFigure(figWeb);
assert(numel(ww) == 1)
% change the figures icon
ww.Icon % returns the current path of the icon
% set a new icon; on Windows systems it must be an .ico file
ww.Icon = fullfile(matlabroot, '\toolbox\matlab\icons\file_open.png')
ww.Icon = fullfile(matlabroot, '\toolbox\matlab\icons\webicon.gif')
% "C:\MATLAB\R2019b\toolbox\compiler\Resources\default_icon.ico"
ww.Icon = fullfile(matlabroot, '\toolbox\matlab\toolstrip\web\image\uicontainer.ico')
figNameOrig = fig.Name; % original figure name
figNameTemp = [fig.Name, tempname('$')]; % creaet a unique temporary figure name (in case of multiple figures with the same name exists
fig.Name = figNameTemp; % rename the figure in case of multiple figures with the same name exists
ww = matlab.internal.webwindowmanager.instance.findAllWebwindows();
webWindow = matlab.internal.webwindow.empty();
for ii = 1:numel(ww)
if strcmp(ww(ii).Title, figNameTemp)
webWindow = ww(ii);
fig.Name = figNameOrig; % restore orignal figure name

Xiangrui Li
Xiangrui Li on 3 Oct 2020
Edited: Xiangrui Li on 13 Oct 2020
Some missing functionality are added gradually. After some test with R2020b, I can conform the following:
  1. figure icon is implemented: hFig.Icon = 'fullFilename.png'
  2. uicontextmenu is there, but I have not used it yet
  3. print() won't work for fiie and clipboard export, but exportgraphics and copygraphics serve the purpose
  4. uitable allows to select cell/row by code, as well as single row selection, although not documented
  5. file/folder DnD can be done with some tricks
I just posted a simple code to do the file drag and drop to uifigure. Comments and suggestion are welcome.

Mark Schoen
Mark Schoen on 30 Sep 2019
Edited: Mark Schoen on 30 Sep 2019
MATLAB has been working to encompass the functionality of the Swing-based framework (including "javacomponent" and "JavaFrame") by adding a whole host of new functions and features. The following link lists some of the most common features you can now access as alternatives to Java Swing:
If you have additional "javacomponent" or "JavaFrame" usage scenarios not covered in the table in the link above, please complete the survey near the top of the page (orange box) to help us better understand your needs. The survey should only take 1–2 minutes to finish.
Jesse Hopkins
Jesse Hopkins on 10 Apr 2020
Edited: Jesse Hopkins on 10 Apr 2020
Please please please address the 'keypressfcn' functionality in edit-box widgets if you haven't already. Unfortunately I can't find my old new-reader posts about this issue, but it goes way back to R14->R2007A udpate. In R14, it was possible to finagle edit-box keypressfcn callback to retreive the current string in the edit-box by toggling focus, thus was a way to validate input on each keystroke. (without toggling focus, the keypressfcn would only see the string since the last 'enter' press). That behavior was removed in R2007A and never came back AFAIK. Thus using built-in matlab capability there is no reliable means to get the current string in a edit widget, since KeyPressFcn only can see the text since the user last pressed 'enter'.
Since R2007A I've been using javacomponent to get at the 'KeyTypedCallback' and using the underlying java object to access the string property, which is reliably updated on each keypress.
If that goes away, please don't leave me stranded with no way to validate input on each keystroke!
P.S. I did submit a bug report on this issue way back when, and it is actually still in the system (00489099). The bug report is shown status "Bug/Enhancement Complete", but I never signed off on it! Still seems to be an issue in R2017B.
Jesse Hopkins
Jesse Hopkins on 9 Sep 2021
I'm pleased to learn that App Designer edit boxes indeed have a valid callback for each keystroke with reliable string values: ValueChangingFcn. Hooray!

Sign in to comment.


Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!