How to "wrap text" on pushbutton string?
9 次查看(过去 30 天)
显示 更早的评论
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).
0 个评论
采纳的回答
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 个)
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!