Fixing an old script containing JavaFrame / JavaContainer
    26 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Jim McIntyre
 el 1 de Jul. de 2025
  
    
    
    
    
    Comentada: Jim McIntyre
 el 2 de Jul. de 2025
            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 
I am aware of the webpage here: Java Swing Alternatives for MATLAB Apps - MATLAB & Simulink
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
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 1 de Jul. de 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.
There are some solutions for changing icons at https://www.mathworks.com/matlabcentral/answers/480115-deprecated-javacomponent-and-javaframe#answer_400110 and https://www.mathworks.com/matlabcentral/answers/499810-how-can-i-change-the-title-bar-icon-of-my-app#answer_454351 . Those solutions might require that uifigure() be used instead of figure()
Más respuestas (0)
Ver también
Categorías
				Más información sobre Programming Utilities en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

