App Designer component generated by code not displaying
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
As a simple example, the expected label from the code below does not display. This is my first attempt to generate a component by code. Also first question to the forum. What am I missing?

methods (Access = private)
function startupFcn(app)
% Display a label as a simple example
lbl = uilabel(app.UIFigure);
lbl.Text = 'Hello, this is a label!';
lbl.Position = [100 300 200 30]; % [x y width height]
lbl.FontSize = 14;
lbl.FontColor = [0 0 1]; % Blue text
lbl = uilabel(app.Panel);
lbl.Text = 'Label inside a panel';
lbl.Position = [20 50 150 22];
end
end
採用された回答
It is conspicuous to me that you are complaining about missing labels, but not about the missing uipanel!. Did you pre-populate the canvas with one? Assuming you did (and that it is named 'Panel') then there's nothing wrong with the code you have shown. Here is what your code gives me.

8 件のコメント
I think your point leads to myself not knowing some fundamental step. If I run the first code in Matlab, I see a label appear. If I run the second code in App Designer, I do not see a label. I must be missing something very basic. My first attempt at creating a component using self written code in App Designer. Dragging components over and letting App Designer write most of the supporting code works fine.
% This create a label if run in Matlab
lbl = uilabel;
lbl.Text = 'Hello, this is a label!';
lbl.Position = [100 300 200 30];
lbl.FontSize = 14;
lbl.FontColor = [0 0 1];
% This does not create a label when added to the default code provided
% when you create a new blank app within App Designer
methods (Access = private)
function startupFcn(app)
lbl = uilabel(app.UIFigure); % Note 'app.UIFigure' in this case
lbl.Text = 'Hello, this is a label!';
lbl.Position = [100 300 200 30];
lbl.FontSize = 14;
lbl.FontColor = [0 0 1];
end
end
What steps did you follow to add the startupFcn to the App Designer code view? Can you share a screenshot of your entire code view screen, or at least a substantial part containing the startupFcn? Mine looks like this:

Bob
2025 年 12 月 10 日
Sorry for not intially sharing more of the code. My steps were open a new app, choose a blank app, choose to add a function, and within the methods declarations then add the startupFcn .
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
end
methods (Access = private)
% I ADDED FROM HERE...
% This does not create a label when added to the default code provided
% when you create a new blank app within App Designer
function startupFcn(app)
lbl = uilabel(app.UIFigure); % Note 'app.UIFigure' in this case
lbl.Text = 'Hello, this is a label!';
lbl.Position = [100 300 200 30];
lbl.FontSize = 14;
lbl.FontColor = [0 0 1];
end
% TO HERE....
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = app1
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
Matt J
2025 年 12 月 10 日
No, the startupFcn is a callback of the app. It cannot be added as an ordinary method. To insert it, right click on the top-level app handle in the Component Browser and select the dropdown options shown:

Bob
2025 年 12 月 10 日
I just now added a panel by sliding one over from the component library, App Designer automatically added the corresponding code, then attemped to display the label in the panel. Still no label. Can it be the code?, or some setting or option not initiated?
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Panel matlab.ui.container.Panel
end
methods (Access = private)
% This does not create a label when added to the default code provided
% when you create a new blank app within App Designer
function startupFcn(app)
lbl = uilabel(app.UIFigure); % Note 'app.UIFigure' in this case
lbl.Text = 'Hello, this is a label!';
lbl.Position = [100 300 200 30];
lbl.FontSize = 14;
lbl.FontColor = [0 0 1];
%%%%% App Designer inserted the Panel under properties, then i added this
% No luck
lbl=unlabel(app.Panel);
lbl.Text = 'Label in panel';
lbl.Position = [20 50 150 22];
end
end
Matt J
2025 年 12 月 10 日
Have you added the startupFcn as a callback, as outlined in my last comment?
Bob
2025 年 12 月 10 日
Perfect! I very much appreciate your insights. Never would I have figured that out!
Bob
Matt J
2025 年 12 月 10 日
You're welcome, but please Accept-click the answer to indicate that it resolved your question.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Develop uifigure-Based Apps についてさらに検索
タグ
参考
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
