How to "wrap text" on pushbutton string?

조회 수: 8 (최근 30일)
Epri Pratiwi
Epri Pratiwi 2020년 8월 17일
댓글: Epri Pratiwi 2020년 8월 17일
I have a long tittle for a file. When I tried to show the tittle on pushbutton, it become like this. I want the rest of tittle goes down or look like in "wrap text" mode (just like in Excel).

채택된 답변

Walter Roberson
Walter Roberson 2020년 8월 17일
편집: Walter Roberson 2020년 8월 17일
Create a figure. Create a uipanel within the figure. Create a uicontrol style text or edit with Max set greater than 1, with parent set to the uipanel. Set the Position property to the height and width you want the pushbutton to have, plus a magic number margin to take into account the outside and decoration of uicontrol style text. Make sure the uicontrol has the right font name and font size that you will be using.
Now wraptext() with the control and the text you want for the button. You will get out a cell array of character vectors that contains the split text.
Option 1:
Now set the string property of the uicontrol to the wrapped text cell array. Set the Position of the uipanel to just enclose the uicontrol. And then use saveas() or print() or exportgraphics() to capture a copy of the rendered text and write out to a file and imread the file, /Or capture() the uipanel into an array. With the array on hand either way, set the CData property of the pushbutton to have an image of the text
Option 2: take the cell array of character vectors and use insertText from the Computer Vision Toolbox to render the text into an array. Then set the CData property of the pushbutton to be the image of the wrapped text.
Afterwards, clean up.
You might have noticed here that:
A) you cannot just pass in an array size and text and ask to wrap it, or render it in wrapped form;
B) pushbuttons do not support multi-line labels, so you have to put in a picture of the text.
But never let it be said that I didn't tell you how to do the task. It is possible.
You might want to consider separating the label into a uicontrol style edit with Enable set to disable. When you do that, you will get scroll bars but the user will not be able to edit. Then put a button without a label.
  댓글 수: 1
Epri Pratiwi
Epri Pratiwi 2020년 8월 17일
Thanks for the info! I will try to use image for the pusbutton that contains the tittle.

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

추가 답변 (1개)

Vladimir Sovkov
Vladimir Sovkov 2020년 8월 17일
편집: Vladimir Sovkov 2020년 8월 17일
Use the cell array with entries containing text fragments to be shown in separate strings.
  댓글 수: 1
Epri Pratiwi
Epri Pratiwi 2020년 8월 17일
I don't think if it's possible. Making a multiline text display is not possible on pushbuttons.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by