How to wrap text within buttons of app-designer

35 ビュー (過去 30 日間)
Leon 2019 年 10 月 19 日
コメント済み: Adam Danz 2021 年 4 月 30 日
Is there a way I can chose to wrap the text in my button to a 2nd row, instead of letting it to overflow outside my button?


Adam Danz
Adam Danz 2019 年 10 月 19 日
編集済み: Adam Danz 2021 年 4 月 30 日
You can make set multi-lined text in a button from within the startup function startupFcn().
The first line below creates two lines of text within the button.
The second line moves the button down and doubles its vertical size. Set the button width and the position of the top of the button from the DesignView.
% Code that executes after component creation
function startupFcn(app, arg1)
app.Button.Text = ['Really long',newline,'button name']; % or sprintf('Really long\nbutton name')
app.Button.Position([2,4]) = app.Button.Position([2,4]) + [-1,1].*app.Button.Position(4);
% If you'd rather the button size to expand upward rather than downward,
% Replace the 2nd line above with
% app.Button.Position(4) = app.Button.Position(4)*2;
As of R2020b multi-line text in buttons can be achieved from Design View (thanks Eric Sargent).
  4 件のコメント
Adam Danz
Adam Danz 2021 年 4 月 30 日
Thanks Eric, I updated my answer to increase visibility.


その他の回答 (1 件)

Eric Sargent
Eric Sargent 2020 年 12 月 9 日
As of R2020b components that support multiline text now support WordWrap, including uibutton.
uilabel, uitextarea, uibutton, uitogglebutton, uicheckbox, uiradiobutton
  1 件のコメント
Adam Danz
Adam Danz 2020 年 12 月 9 日
+1, thanks for the update, Eric.



Find more on Package and Share Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by