Fixing an old script containing JavaFrame / JavaContainer

23 visualizzazioni (ultimi 30 giorni)
I've inherited an old set of Matlab scripts from around 2010. The scripts contain code like the following. I am trying to understand and update the code so that I can make these scripts run in Matlab 2025.
I would appreciate any guidance on what these scripts are doing and how to replace the JavaFrame / JavaContainer entries that cause errors
try
vi=openfig('VersionInfo.fig','reuse','invisible');
movegui(vi,'center')
jvi = handle(get(vi,'JavaFrame'),'callbackproperties');
import java.awt.*
import javax.swing.*
jvi.setFigureIcon(ImageIcon(getfigureicon));
and
%move the figure to the center
movegui(CTP,'center')
%create the figure icon
warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame')
jCTP = handle(get(CTP,'JavaFrame'),'callbackproperties');
import java.awt.*
import javax.swing.*
jCTP.setFigureIcon(ImageIcon(getfigureicon));
%obtain the java container of the toolbar, so that a combo box can
%be placed there
htb = findobj(CTP,'tag','figtb');
jtb = handle(get(get(htb,'JavaContainer'),'ComponentPeer'),...
'callbackproperties');
if ~isempty(jtb)
getpref('CTW','TextVisible',0);
if getpref('CTW','TextVisible')
%this sets whether or not the user can see text labels on
%the buttons -- set as inverse because togglePreferences
%will switch it to the correct value
set(findobj('tag','TextVisible'),'checked','off')
else
set(findobj('tag','TextVisible'),'checked','on')
end %if statement
togglePreferences(findobj('tag','TextVisible'))
%separate the combo box from the buttons
jtb.addSeparator;
jtext=JLabel('Current Scan:');
jtb.add(jtext);
%create the combo box
jcb=JComboBox('No Scans');
jcb.setMinimumSize(Dimension(0,18))
%add the combo box to the toolbar
jtb.add(jcb);
jcb=handle(jcb,'callbackproperties');
%save the java handle to the toolbar for later use
set(htb,'userdata',jcb)
set(jtb,'AncestorAddedCallback',@undockToolbar );
jtb.setFloatable(1);
jtb.repaint
jtb.revalidate
end %if statement
else

Risposta accettata

Walter Roberson
Walter Roberson il 1 Lug 2025
All Java functionality associated with MATLAB figures is gone, never to return.
jvi.setFigureIcon(ImageIcon(getfigureicon));
That code is intended to change the icon image of the executable in the dock or taskbar.
  1 Commento
Jim McIntyre
Jim McIntyre il 2 Lug 2025
Thank you.
I understand about the loss of Java functionality. I will give these a look.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming Utilities in Help Center e File Exchange

Prodotti


Release

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by