Fixing an old script containing JavaFrame / JavaContainer

조회 수: 23 (최근 30일)
Jim McIntyre
Jim McIntyre 2025년 7월 1일
댓글: Jim McIntyre 2025년 7월 2일
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.
  댓글 수: 1
Jim McIntyre
Jim McIntyre 2025년 7월 2일
Thank you.
I understand about the loss of Java functionality. I will give these a look.

댓글을 달려면 로그인하십시오.

추가 답변 (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