Fixing an old script containing JavaFrame / JavaContainer

32 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2025-7-1
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming Utilities 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by