Clear Filters
Clear Filters

macOS compiled application docker icon is not set correctly for uifigure

1 view (last 30 days)
I am using the Application Compiler APPS to build our application on both mac (mac also uses compiler.package.installer)and windows. We now have a mixture of figure and uifigures for the different tools in the application. When the application is compiled, installed, and opened on macOS Ventura the uifigure figures have the matlab icon on the Docker bar instead of our icon (orange with squiggles). Figure based figures do work correctly. I had to implement the following code from this answer to get the uifigure icons correct on the windows computer, but on mac it is still broken. I have tried using both .ico and icns images for the icon, with the same result.
hUIFig = uifigure; % allow this to load first (run it separately from the below code)
% Find the CEF window for the running app's figure: this idea
% comes from DesktopFigureService MALTAB internal class (courtesy)
cefWindowList = matlab.internal.webwindowmanager.instance.windowList;
url = matlab.ui.internal.FigureServices.getFigureURL(hUIFig);
[idx] = arrayfun(@(ww)strcmp(url,ww.URL), cefWindowList);
hWin = cefWindowList(idx);
hWin.Icon = which('your-icon.ico'); % must be ico file

Answers (1)

Aditya
Aditya on 25 Jun 2024 at 14:47
It sounds like you're experiencing an issue with setting the custom icon for uifigure windows in a compiled MATLAB application on macOS. This is a common issue due to the way MATLAB handles uifigure icons differently across platforms. The solution you mentioned works on Windows, but macOS might need a different approach.
  1. Check the Icon Format : Ensure that you are using the correct format for macOS. While .ico files work for Windows, macOS typically uses .icns files for icons. Ensure your .icns file is correctly formatted and not corrupted.
  2. Set the Icon in the Compiled Application : Make sure you are setting the icon in the correct place in your code. It should be set after the uifigure is created but before it is displayed.
  3. Use MATLAB's Internal Methods : Sometimes, using MATLAB's internal methods can help. The following code snippet demonstrates how to set the icon for a uifigure on macOS:
hUIFig = uifigure; % Create the uifigure
drawnow; % Ensure the figure is fully initialized
% Find the CEF window for the running app's figure
cefWindowList = matlab.internal.webwindowmanager.instance.windowList;
url = matlab.ui.internal.FigureServices.getFigureURL(hUIFig);
idx = arrayfun(@(ww)strcmp(url, ww.URL), cefWindowList);
hWin = cefWindowList(idx);
% Set the icon (use the correct path to your .icns file)
hWin.Icon = fullfile(pwd, 'your-icon.icns');

Categories

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

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!